コード例 #1
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
        private Request CreateModel(RequestBindingModel model, Request request, CTODatabase context)
        {
            request.ClientId    = model.ClientId;
            request.RequestName = model.RequestName;
            request.RequestCost = model.RequestCost;
            request.DateFrom    = model.DateFrom;
            request.DateTo      = model.DateTo;

            if (model.Id.HasValue)
            {
                var requestWorks = context.RequestWorks.Where(rec => rec.RequestId == model.Id.Value).ToList();
                context.RequestWorks.RemoveRange(requestWorks.Where(rec => !model.RequestWorks.ContainsKey(rec.WorkId)).ToList());
                context.SaveChanges();
                foreach (var updateComponent in requestWorks)
                {
                    model.RequestWorks.Remove(updateComponent.WorkId);
                }
                context.SaveChanges();
            }
            foreach (var pc in model.RequestWorks)
            {
                context.RequestWorks.Add(new RequestWork
                {
                    RequestId = request.Id,
                    WorkId    = pc.Key,
                });
                context.SaveChanges();
            }

            return(request);
        }
コード例 #2
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 public void Update(RequestBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 var element = context.Requests.Include(rec => rec.RequestWorks)
                               .ThenInclude(rec => rec.Work).FirstOrDefault(rec => rec.Id == model.Id);
                 if (element == null)
                 {
                     throw new Exception("Заявка не найдена");
                 }
                 CreateModel(model, element, context);
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
コード例 #3
0
 public void Insert(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         context.Works.Add(CreateModel(model, new Work()));
         context.SaveChanges();
     }
 }
コード例 #4
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 public void Insert(CostBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         context.Costs.Add(CreateModel(model, new Cost()));
         context.SaveChanges();
     }
 }
コード例 #5
0
 public void Update(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         var element = context.Works.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Такого ремонта нет");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
コード例 #6
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 public void Update(CostBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         var element = context.Costs.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Статья затрат не найдена");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
コード例 #7
0
 public void Update(WorkerBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         var element = context.Workers.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Сотрудник не найден");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
コード例 #8
0
 public void Delete(WorkBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         Work element = context.Works.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Works.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Такого ремонта нет");
         }
     }
 }
コード例 #9
0
ファイル: CostStorage.cs プロジェクト: Unforgettable01/CTO
 public void Delete(CostBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         Cost element = context.Costs.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Costs.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Статья затрат не найдена");
         }
     }
 }
コード例 #10
0
 public void Delete(WorkerBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         Worker element = context.Workers.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Workers.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Сотрудник не найден");
         }
     }
 }
コード例 #11
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 public void Delete(RequestBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         Request element = context.Requests.Include(rec => rec.RequestWorks)
                           .ThenInclude(rec => rec.Work).FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Requests.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Заявка не найдена");
         }
     }
 }
コード例 #12
0
ファイル: RequestStorage.cs プロジェクト: Unforgettable01/CTO
 public void Insert(RequestBindingModel model)
 {
     using (var context = new CTODatabase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 Request request = CreateModel(model, new Request());
                 context.Requests.Add(request);
                 context.SaveChanges();
                 CreateModel(model, request, context);
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }