コード例 #1
0
        private Shipment CreateModel(ShipmentBindingModel model, Shipment shipment, MebelDatabase context)
        {
            shipment.Date  = model.Date;
            shipment.Name  = model.Name;
            shipment.Price = model.Price;

            if (shipment.Id == 0)
            {
                context.Shipments.Add(shipment);
                context.SaveChanges();
            }

            if (model.Id.HasValue)
            {
                var shipmentGarnitures = context.ShipmentGarnitures
                                         .Where(rec => rec.ShipmentId == model.Id.Value)
                                         .ToList();

                context.ShipmentGarnitures.RemoveRange(shipmentGarnitures.ToList());

                context.SaveChanges();
            }

            foreach (var shipmentGarniture in model.ShipmentGarnitures)
            {
                context.ShipmentGarnitures.Add(new ShipmentGarniture
                {
                    ShipmentId  = shipment.Id,
                    GarnitureId = shipmentGarniture.Key,
                    Count       = shipmentGarniture.Value.Item2
                });
                context.SaveChanges();
            }
            return(shipment);
        }
コード例 #2
0
        private Supply CreateModel(SupplyBindingModel model, Supply supply, MebelDatabase context)
        {
            supply.Date  = model.Date;
            supply.Name  = model.Name;
            supply.Price = model.Price;

            if (supply.Id == 0)
            {
                context.Supplys.Add(supply);
                context.SaveChanges();
            }

            if (model.Id.HasValue)
            {
                var supplyMaterials = context.SupplyMaterials
                                      .Where(rec => rec.SupplyId == model.Id.Value)
                                      .ToList();

                context.SupplyMaterials.RemoveRange(supplyMaterials.ToList());

                context.SaveChanges();
            }

            foreach (var supplyMaterial in model.SupplyMaterials)
            {
                context.SupplyMaterials.Add(new SupplyMaterial
                {
                    SupplyId   = supply.Id,
                    MaterialId = supplyMaterial.Key,
                    Count      = supplyMaterial.Value.Item2
                });
                context.SaveChanges();
            }
            return(supply);
        }
コード例 #3
0
        public void Update(ModuleBindingModel model)
        {
            using (var context = new MebelDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var module = context.Modules.FirstOrDefault(rec => rec.Id == model.Id);

                        if (module == null)
                        {
                            throw new Exception("Модуль не найден");
                        }

                        CreateModel(model, module, context);
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
コード例 #4
0
        public void Update(SupplyBindingModel model)
        {
            using (var context = new MebelDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var supply = context.Supplys.FirstOrDefault(rec => rec.Id == model.Id);

                        if (supply == null)
                        {
                            throw new Exception("Поставка не найдена");
                        }

                        CreateModel(model, supply, context);
                        context.SaveChanges();

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
コード例 #5
0
 public void Insert(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         context.Mebel.Add(CreateModel(model, new Mebel()));
         context.SaveChanges();
     }
 }
コード例 #6
0
 public void Insert(ProviderBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         context.Providers.Add(CreateModel(model, new Provider()));
         context.SaveChanges();
     }
 }
コード例 #7
0
 public void Update(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         var element = context.Mebel.FirstOrDefault(rec => rec.Id == model.Id);
         if (element == null)
         {
             throw new Exception("Мебель не найдена");
         }
         CreateModel(model, element);
         context.SaveChanges();
     }
 }
コード例 #8
0
        public void Delete(ModuleBindingModel model)
        {
            using (var context = new MebelDatabase())
            {
                var module = context.Modules.FirstOrDefault(rec => rec.Id == model.Id);

                if (module == null)
                {
                    throw new Exception("Модуль не найден");
                }

                context.Modules.Remove(module);
                context.SaveChanges();
            }
        }
コード例 #9
0
 public void Delete(SupplyBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         Supply element = context.Supplys.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Supplys.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Поступление не найдено");
         }
     }
 }
コード例 #10
0
 public void Delete(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         Mebel element = context.Mebel.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Mebel.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Мебель не найдена");
         }
     }
 }
コード例 #11
0
 public void Delete(ProviderBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         Provider element = context.Providers.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Providers.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Поставщик не найден");
         }
     }
 }
コード例 #12
0
 public void Delete(ShipmentBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         Shipment element = context.Shipments.FirstOrDefault(rec => rec.Id == model.Id);
         if (element != null)
         {
             context.Shipments.Remove(element);
             context.SaveChanges();
         }
         else
         {
             throw new Exception("Отгрузка не найдено");
         }
     }
 }
コード例 #13
0
 public void Insert(ModuleBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 CreateModel(model, new Module(), context);
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }