public void DeleteCost(CostInspectionsBindingModel model) { using (var context = new Database()) { CostInspection element = context.CostInspections.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.CostInspections.Remove(element); context.SaveChanges(); } else { throw new Exception("Элемент не найден"); } } }
public CostInspectionsViewModels GetElement(CostInspectionsBindingModel model) { if (model == null) { return(null); } using (var context = new Database()) { var product = context.CostInspections .FirstOrDefault(rec => rec.Id == model.Id || (rec.CostId == model.CostId && rec.InspectionId == model.InspectionId)); return(product != null ? new CostInspectionsViewModels { Id = product.Id, Cena = product.Cena, CostId = product.CostId, InspectionId = product.InspectionId } : null); } }