Files
School/Anul 2/Semestrul 2/ISS/Lab6/UBB-SE-2024-922-2/ProfessionalProfile/repo/VolunteeringRepo.cs
T
2024-08-31 12:07:21 +03:00

59 lines
1.7 KiB
C#

using Microsoft.EntityFrameworkCore;
using ProfessionalProfile.DatabaseContext;
using ProfessionalProfile.Domain;
using ProfessionalProfile.Interfaces;
namespace ProfessionalProfile.repo
{
public class VolunteeringRepo : IVolunteeringRepo
{
private readonly IDbContextFactory<DataContext> _contextFactory;
public VolunteeringRepo(IDbContextFactory<DataContext> contextFactory)
{
_contextFactory = contextFactory;
}
public void Add(Volunteering item)
{
using (var context = _contextFactory.CreateDbContext())
{
context.Volunteering.Add(item);
context.SaveChanges();
}
}
public void Delete(int id)
{
using (var context = _contextFactory.CreateDbContext())
{
var volunteering = context.Volunteering.Find(id);
context.Volunteering.Remove(volunteering);
context.SaveChanges();
}
}
public ICollection<Volunteering> GetAll()
{
using (var context = _contextFactory.CreateDbContext())
{
return context.Volunteering.ToList();
}
}
public Volunteering GetById(int id)
{
using (var context = _contextFactory.CreateDbContext())
{
return context.Volunteering.Find(id);
}
}
public void Update(Volunteering volunteering)
{
using (var context = _contextFactory.CreateDbContext())
{
context.Volunteering.Update(volunteering);
context.SaveChanges();
}
}
}
}