Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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;
                    }
                }
            }
        }
Exemplo n.º 4
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;
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void Insert(MebelBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         context.Mebel.Add(CreateModel(model, new Mebel()));
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public List <ProviderViewModel> GetFullList()
 {
     using (var context = new MebelDatabase())
     {
         return(context.Providers
                .Select(CreateModel).ToList());
     }
 }
Exemplo n.º 7
0
 public void Insert(ProviderBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         context.Providers.Add(CreateModel(model, new Provider()));
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public List <ShipmentViewModel> GetFullList()
 {
     using (var context = new MebelDatabase())
     {
         return(context.Shipments
                .Include(rec => rec.ShipmentGarnitures)
                .ThenInclude(rec => rec.Garniture)
                .Select(CreateModel)
                .ToList());
     }
 }
Exemplo n.º 9
0
 public List <ModuleViewModel> GetFullList()
 {
     using (var context = new MebelDatabase())
     {
         return(context.Modules
                .Include(rec => rec.ModuleMaterial)
                .Include(rec => rec.ModuleMebel)
                .Select(CreateModel)
                .ToList());
     }
 }
Exemplo n.º 10
0
 public List <SupplyViewModel> GetFullList()
 {
     using (var context = new MebelDatabase())
     {
         return(context.Supplys
                .Include(rec => rec.SupplyMaterials)
                .ThenInclude(rec => rec.Material)
                .Select(CreateModel)
                .ToList());
     }
 }
Exemplo n.º 11
0
 public List <ProviderViewModel> GetFilteredList(ProviderBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         return(context.Providers
                .Where(rec => rec.FullName.Contains(model.FullName))
                .Select(CreateModel).ToList());
     }
 }
Exemplo n.º 12
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();
     }
 }
Exemplo n.º 13
0
 public List <GarnitureViewModel> GetFullList()
 {
     using (var context = new MebelDatabase())
     {
         return(context.Garniture
                .Include(rec => rec.GarnitureMaterial)
                .ThenInclude(rec => rec.Material)
                .Include(rec => rec.GarnitureMebel)
                .ThenInclude(rec => rec.Mebel)
                .Select(CreateModel)
                .ToList());
     }
 }
Exemplo n.º 14
0
 public List <MebelViewModel> GetFullList()
 {
     using (var context = new MebelDatabase())
     {
         return(context.Mebel
                .Select(rec => new MebelViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             Price = rec.Price
         })
                .ToList());
     }
 }
Exemplo n.º 15
0
 public ProviderViewModel GetElement(ProviderBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         var provider = context.Providers
                        .FirstOrDefault(rec => rec.Id == model.Id || rec.FullName == model.FullName);
         return(provider != null?
                CreateModel(provider) : null);
     }
 }
Exemplo n.º 16
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();
            }
        }
Exemplo n.º 17
0
 public List <SupplyViewModel> GetFilteredList(SupplyBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         return(context.Supplys
                .Include(rec => rec.SupplyMaterials)
                .ThenInclude(rec => rec.Material)
                .Where(rec => rec.Date >= model.DateFrom && rec.Date <= model.DateTo)
                .Select(CreateModel).ToList());
     }
 }
Exemplo n.º 18
0
 public List <ShipmentViewModel> GetFilteredList(ShipmentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         return(context.Shipments
                .Include(rec => rec.ShipmentGarnitures)
                .ThenInclude(rec => rec.Garniture)
                .Where(rec => rec.Date >= model.DateFrom && rec.Date <= model.DateTo)
                .Select(CreateModel).ToList());
     }
 }
Exemplo n.º 19
0
 public SupplyViewModel GetElement(SupplyBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         var supply = context.Supplys
                      .Include(rec => rec.SupplyMaterials)
                      .ThenInclude(rec => rec.Material)
                      .FirstOrDefault(rec => rec.Id == model.Id);
         return(supply != null?
                CreateModel(supply) : null);
     }
 }
Exemplo n.º 20
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("Поставщик не найден");
         }
     }
 }
Exemplo n.º 21
0
 public ShipmentViewModel GetElement(ShipmentBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         var shipment = context.Shipments
                        .Include(rec => rec.ShipmentGarnitures)
                        .ThenInclude(rec => rec.Garniture)
                        .FirstOrDefault(rec => rec.Id == model.Id);
         return(shipment != null?
                CreateModel(shipment) : null);
     }
 }
Exemplo n.º 22
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("Мебель не найдена");
         }
     }
 }
Exemplo n.º 23
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("Отгрузка не найдено");
         }
     }
 }
Exemplo n.º 24
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("Поступление не найдено");
         }
     }
 }
Exemplo n.º 25
0
        public List <ModuleViewModel> GetFilteredList(ModuleBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new MebelDatabase())
            {
                return(context.Modules
                       .Include(rec => rec.ModuleMaterial)
                       .Include(rec => rec.ModuleMebel)
                       .Where(rec => rec.Id == model.Id)
                       .Select(CreateModel)
                       .ToList());
            }
        }
Exemplo n.º 26
0
 public List <MebelViewModel> GetFilteredList(MebelBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         return(context.Mebel
                .Where(rec => rec.Name.Contains(model.Name))
                .Select(rec => new MebelViewModel
         {
             Id = rec.Id,
             Name = rec.Name,
             Price = rec.Price
         })
                .ToList());
     }
 }
Exemplo n.º 27
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;
             }
         }
     }
 }
Exemplo n.º 28
0
 public MebelViewModel GetElement(MebelBindingModel model)
 {
     if (model == null)
     {
         return(null);
     }
     using (var context = new MebelDatabase())
     {
         var component = context.Mebel
                         .FirstOrDefault(rec => rec.Name == model.Name || rec.Id == model.Id);
         return(component != null ?
                new MebelViewModel
         {
             Id = component.Id,
             Name = component.Name,
             Price = component.Price
         } :
                null);
     }
 }
Exemplo n.º 29
0
        public ModuleViewModel GetElement(ModuleBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new MebelDatabase())
            {
                var module = context.Modules
                             .Include(rec => rec.ModuleMaterial)
                             .ThenInclude(rec => rec.Material)
                             .Include(rec => rec.ModuleMebel)
                             .ThenInclude(rec => rec.Mebel)
                             .FirstOrDefault(rec => rec.Id == model.Id);

                return(module != null?
                       CreateModel(module) :
                           null);
            }
        }