Пример #1
0
        public void Update(GarnitureBindingModel model)
        {
            using (var context = new MebelDatabase())
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var module = context.Garniture.FirstOrDefault(rec => rec.Id == model.Id);

                        if (module == null)
                        {
                            throw new Exception("Гарнитур не найден");
                        }

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

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }
        }
Пример #2
0
 public void CreateOrUpdate(GarnitureBindingModel model)
 {
     if (model.Id.HasValue)
     {
         _garnitureStorage.Update(model);
     }
     else
     {
         _garnitureStorage.Insert(model);
     }
 }
Пример #3
0
        public void Delete(GarnitureBindingModel model)
        {
            var garniture = _garnitureStorage.GetElement(new GarnitureBindingModel
            {
                Id = model.Id
            });

            if (garniture == null)
            {
                throw new Exception("Гарнитур не найден");
            }
            _garnitureStorage.Delete(model);
        }
Пример #4
0
 public List <GarnitureViewModel> Read(GarnitureBindingModel model)
 {
     if (model == null)
     {
         return(_garnitureStorage.GetFullList());
     }
     if (model.Id.HasValue)
     {
         return(new List <GarnitureViewModel> {
             _garnitureStorage.GetElement(model)
         });
     }
     return(_garnitureStorage.GetFilteredList(model));
 }
Пример #5
0
        public void Delete(GarnitureBindingModel model)
        {
            using (var context = new MebelDatabase())
            {
                var module = context.Garniture.FirstOrDefault(rec => rec.Id == model.Id);

                if (module == null)
                {
                    throw new Exception("Гарнитур не найден");
                }

                context.Garniture.Remove(module);
                context.SaveChanges();
            }
        }
Пример #6
0
        public List <GarnitureViewModel> GetFilteredList(GarnitureBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new MebelDatabase())
            {
                return(context.Garniture
                       .Include(rec => rec.GarnitureMaterial)
                       .Include(rec => rec.GarnitureMebel)
                       .Where(rec => rec.Id == model.Id)
                       .Select(CreateModel)
                       .ToList());
            }
        }
Пример #7
0
 public void Insert(GarnitureBindingModel model)
 {
     using (var context = new MebelDatabase())
     {
         using (var transaction = context.Database.BeginTransaction())
         {
             try
             {
                 CreateModel(model, new Garniture(), context);
                 context.SaveChanges();
                 transaction.Commit();
             }
             catch
             {
                 transaction.Rollback();
                 throw;
             }
         }
     }
 }
Пример #8
0
        public GarnitureViewModel GetElement(GarnitureBindingModel model)
        {
            if (model == null)
            {
                return(null);
            }

            using (var context = new MebelDatabase())
            {
                var module = context.Garniture
                             .Include(rec => rec.GarnitureMaterial)
                             .ThenInclude(rec => rec.Material)
                             .Include(rec => rec.GarnitureMebel)
                             .ThenInclude(rec => rec.Mebel)
                             .FirstOrDefault(rec => rec.Id == model.Id);

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