Пример #1
0
        public ActionResult Create()
        {
            var model = new AdminEditProductClassViewModel
            {
                AllAttribute = GetProductClassAttribute()
            };

            return(View(model));
        }
Пример #2
0
        public ActionResult Edit(Guid Id)
        {
            var productclass = _productSevice.GetProductClass(Id);

            if (productclass == null)
            {
                return(RedirectToAction("index"));
            }

            var model = new AdminEditProductClassViewModel
            {
                Id           = productclass.Id,
                Colour       = productclass.Colour,
                Description  = productclass.Description,
                Image        = productclass.Image,
                IsLocked     = productclass.IsLocked,
                Name         = productclass.Name,
                AllAttribute = GetProductClassAttribute(productclass)
            };


            return(View(model));
        }
Пример #3
0
        public ActionResult Edit(AdminEditProductClassViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var productClass = _productSevice.GetProductClass(model.Id);
                        if (productClass == null)
                        {
                            return(RedirectToAction("index"));
                        }

                        model.Image = productClass.Image;

                        productClass.Name        = model.Name;
                        productClass.Image       = model.Image;
                        productClass.Description = model.Description;
                        productClass.Colour      = model.Colour;
                        productClass.IsLocked    = model.IsLocked;

                        _productSevice.Update(productClass);

                        _productSevice.DelAllAttributeForProductClass(productClass.Id);
                        if (model.AllAttribute != null)
                        {
                            foreach (var it in model.AllAttribute)
                            {
                                if (it.IsCheck)
                                {
                                    var a = new ProductClassAttribute
                                    {
                                        ProductAttributeId = it.Id,
                                        ProductClassId     = productClass.Id,
                                        IsShow             = it.IsShow,
                                    };

                                    _productSevice.Add(a);
                                }
                            }
                        }


                        unitOfWork.Commit();

                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = "Thành công cập nhật nhóm sản phẩm",
                            MessageType = GenericMessages.success
                        };
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LoggingService.Error(ex.Message);

                        ModelState.AddModelError("", "Lỗi khi thêm nhóm sản phẩm");
                    }
                }
            }

            if (model.AllAttribute != null)
            {
                foreach (var it in model.AllAttribute)
                {
                    it.Name = _productSevice.GetAttribute(it.Id).LangName;
                }
            }

            return(View(model));
        }
Пример #4
0
        public ActionResult Create(AdminEditProductClassViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        var productClass = new ProductClass
                        {
                            Name        = model.Name,
                            Image       = model.Image,
                            Description = model.Description,
                            Colour      = model.Colour,
                            IsLocked    = model.IsLocked
                        };

                        _productSevice.Add(productClass);

                        if (model.AllAttribute != null)
                        {
                            foreach (var it in model.AllAttribute)
                            {
                                if (it.IsCheck)
                                {
                                    var a = new ProductClassAttribute
                                    {
                                        ProductAttributeId = it.Id,
                                        ProductClassId     = productClass.Id,
                                        IsShow             = it.IsShow,
                                    };

                                    _productSevice.Add(a);
                                }
                            }
                        }


                        unitOfWork.Commit();

                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = "Thành công thêm nhóm sản phẩm",
                            MessageType = GenericMessages.success
                        };

                        return(RedirectToAction("Index"));
                    }
                    catch
                    {
                        unitOfWork.Rollback();

                        ModelState.AddModelError("", "Lỗi khi thêm nhóm sản phẩm");
                    }
                }
            }

            foreach (var it in model.AllAttribute)
            {
                it.Name = _productSevice.GetAttribute(it.Id).LangName;
            }
            return(View(model));
        }