public void Delete(int? id) { using (var ctx = new InventorySystemMaintenanceEntities()) { if (id != null) { var item = ctx.Supplier.FirstOrDefault(P => P.Id == id); ctx.Entry(item).State = System.Data.EntityState.Deleted; ctx.SaveChanges(); } } }
public Supplier Insert(string supplierCode, string name, string company , string phoneNo, string fax, string email, string address, string postcode , string state, string country, string website, DateTime? dateCreated , DateTime? dateModified, string createdBy, string modifiedBy, string remarks) { using (var ctx = new InventorySystemMaintenanceEntities()) { Supplier item = new Supplier(); if (!String.IsNullOrEmpty(supplierCode)) { item.SupplierCode = supplierCode; } if (!String.IsNullOrEmpty(name)) { item.Name = name; } if (!String.IsNullOrEmpty(company)) { item.Company = company; } if (!String.IsNullOrEmpty(phoneNo)) { item.PhoneNo = phoneNo; } if (!String.IsNullOrEmpty(fax)) { item.Fax = fax; } if (!String.IsNullOrEmpty(email)) { item.Email = email; } if (!String.IsNullOrEmpty(address)) { item.Address = address; } if (!String.IsNullOrEmpty(postcode)) { item.Postcode = postcode; } if (!String.IsNullOrEmpty(state)) { item.State = state; } if (!String.IsNullOrEmpty(country)) { item.Country = country; } if (!String.IsNullOrEmpty(website)) { item.Website = website; } if (dateCreated != null) { item.DateCreated = dateCreated; } if (dateModified != null) { item.DateModified = dateModified; } if (!String.IsNullOrEmpty(createdBy)) { item.CreatedBy = createdBy; } if (!String.IsNullOrEmpty(modifiedBy)) { item.ModifiedBy = modifiedBy; } if (!String.IsNullOrEmpty(remarks)) { item.Remarks = remarks; } ctx.Entry(item).State = System.Data.EntityState.Added; ctx.SaveChanges(); return item; } }