Beispiel #1
0
 public ActionResult Edit(GoodsCategoryViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     try
     {
         using (var db = new SmDbContext())
         {
             var entity = db.GoodsCategories.FirstOrDefault(x => x.Id == model.Id);
             if (entity == null)
             {
                 entity = new GoodsCategory();
                 db.GoodsCategories.Add(entity);
             }
             entity.Name        = model.Name;
             entity.Description = model.Description;
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Name", ex);
         return(View(model));
     }
 }
Beispiel #2
0
        public GoodsCategoryViewModel UpdateGoodsCategory(GoodsCategoryViewModel model)
        {
            GoodsCategory category = this._unitOfWork.GoodsCategoryRepository.GetGoodsCategoryById(model.Id);

            category.Name        = model.Name;
            category.GoodsTypeId = model.GoodsTypeId;
            this._unitOfWork.SaveChanges();
            return(category);
        }
Beispiel #3
0
        public GoodsCategoryViewModel CreateGoodsCategory(GoodsCategoryViewModel model)
        {
            GoodsCategory category = new GoodsCategory();

            category.Name        = model.Name;
            category.GoodsTypeId = model.GoodsTypeId;
            this._unitOfWork.GoodsCategoryRepository.Create(category);
            this._unitOfWork.SaveChanges();
            return(category);
        }
Beispiel #4
0
        public IEnumerable <GoodsCategoryViewModel> GetAllGoodsCategories()
        {
            List <GoodsCategoryViewModel> list = new List <GoodsCategoryViewModel>();

            foreach (var item in this._unitOfWork.GoodsCategoryRepository.Read())
            {
                GoodsCategoryViewModel category = new GoodsCategoryViewModel();
                category.GoodsTypeId = item.GoodsTypeId;
                category.Id          = item.Id;
                category.Name        = item.Name;
                list.Add(category);
            }
            return(list);
        }
        public IActionResult Edit(GoodsCategoryViewModel model)
        {
            if (_repository.Exists(model.Name))
            {
                ViewBag.Error = "Такое имя уже есть";
                return(View(model));
            }

            if (_repository.Rename(model.Id, model.Name))
            {
                return(RedirectToAction("Index"));
            }

            ViewBag.Error = "Произошла неизвестная ошибка, обратитесь в поддержку";
            return(View(model));
        }
Beispiel #6
0
        public ActionResult EditOnPost(GoodsCategoryViewModel editModel)
        {
            var model = new GoodsCategory
            {
                Id          = editModel.Id,
                ParentId    = editModel.ParentId,
                Descirption = editModel.Descirption,
                Name        = editModel.Name,
                Sort        = editModel.Sort,
                ShowIndex   = editModel.ShowIndex,
                GoodsTypeId = editModel.GoodsTypeId
            };

            var result = new DataJsonResult();

            if (editModel.Id == Guid.Empty)
            {
                _goodsCategoryService.CreateCategory(model);
            }
            else
            {
                _goodsCategoryService.UpdateCategory(model);
            }

            if (model.Id == Guid.Empty)
            {
                result.ErrorMessage = "输入数据错误";
                result.Success      = false;
            }
            else
            {
                //处理主图图片关联
                _storageFileService.ReplaceFile(model.Id, MallModule.Key, MallModule.DisplayName, editModel.CategoryImage, CategoryImage);

                result.Data = model.Id;
            }

            return(Json(result));
        }
Beispiel #7
0
 public void DeleteGoodsCategory(GoodsCategoryViewModel model)
 {
     this._unitOfWork.GoodsCategoryRepository.Delete(model.Id);
     this._unitOfWork.SaveChanges();
 }