52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|
|
}
|