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));
 }
        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();
            }
        }
        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());
            }
        }
 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;
             }
         }
     }
 }
        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);
            }
        }