Пример #1
0
        public ActionResult Edit(GoodEditModel goodEditModel, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                goodEditModel.Date = DateTime.Now;

                Mapper.CreateMap <GoodEditModel, GoodDTO>()
                .ForMember("Category",
                           opt => opt.MapFrom(v => _categoryLogic.Get(v.CategoryId)))
                .ForMember("Color",
                           opt => opt.MapFrom(v => _colorLogic.Get(v.ColorId)));

                var good = Mapper.Map <GoodEditModel, GoodDTO>(goodEditModel);
                good.OrderItems = _goodLogic.Get(goodEditModel.Id).OrderItems;
                if (upload != null && upload.ContentLength > 0)
                {
                    good.ImageType = upload.ContentType;

                    using (var reader = new BinaryReader(upload.InputStream))
                    {
                        good.Image = reader.ReadBytes(upload.ContentLength);
                    }
                }

                _goodLogic.Edit(good);

                return(RedirectToAction("Index"));
            }
            return(View(goodEditModel));
        }
Пример #2
0
        public ActionResult AddOrUpdate(int id = 0)
        {
            GoodEditModel model = new GoodEditModel()
            {
                Good          = goodRepository.Get(id),
                Categories    = categoryRepository.GetAll(),
                Manufacturers = manufacturerRepository.GetAll()
            };

            if (id == 0)
            {
                return(View(new GoodEditModel()
                {
                    Good = new Good(), Categories = categoryRepository.GetAll(), Manufacturers = manufacturerRepository.GetAll()
                }));
            }
            return(View(model));
        }