Exemplo n.º 1
0
        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("Элемент не найден");
                }
            }
        }
Exemplo n.º 2
0
 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);
     }
 }