COP_Petrushin_PIbd-32/Models/Repositories/ManufacturerRepository.cs

52 lines
1.3 KiB
C#
Raw Normal View History

2024-10-30 13:34:23 +04:00
using Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Data.Repositories
{
public class ManufacturerRepository : IManufacturerRepository
{
private readonly ApplicationDbContext _context;
public ManufacturerRepository(ApplicationDbContext context)
{
_context = context;
}
public IEnumerable<Manufacturer> GetAllManufacturers()
{
return _context.Manufacturers.ToList();
}
public Manufacturer GetManufacturerById(int id)
{
return _context.Manufacturers.Find(id);
}
public void AddManufacturer(Manufacturer manufacturer)
{
_context.Manufacturers.Add(manufacturer);
_context.SaveChanges();
}
public void UpdateManufacturer(Manufacturer manufacturer)
{
_context.Manufacturers.Update(manufacturer);
_context.SaveChanges();
}
public void DeleteManufacturer(int id)
{
var manufacturer = _context.Manufacturers.Find(id);
if (manufacturer != null)
{
_context.Manufacturers.Remove(manufacturer);
_context.SaveChanges();
}
}
}
}