public void Delete(int id) { Data.Models.PartSupplier supplier = this.dataContext.Suppliers.Find(id); if (supplier == null) { throw new System.NullReferenceException($"Cannot find supplier with id {id}"); } this.dataContext.Suppliers.Remove(supplier); this.dataContext.SaveChanges(); }
public void Edit(int id, string name, bool isImporter) { Data.Models.PartSupplier supplier = this.dataContext.Suppliers.Find(id); if (supplier == null) { throw new System.NullReferenceException($"Cannot find supplier with id {id}"); } supplier.Name = name; supplier.UsesImportedParts = isImporter; this.dataContext.Entry(supplier).State = Microsoft.EntityFrameworkCore.EntityState.Modified; this.dataContext.SaveChanges(); }
public SupplierModel GetById(int id) { Data.Models.PartSupplier supplier = this.dataContext.Suppliers.Find(id); if (supplier == null) { throw new System.NullReferenceException($"Cannot find supplier with id {id}"); } return(new SupplierModel { IsImporter = supplier.UsesImportedParts, Id = supplier.Id, Name = supplier.Name, }); }