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