public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var category = _categoryLogic.Get(id); if (category == null) { return(HttpNotFound()); } return(View(category)); }
public GoodDTO GoodCreateModelToGood(GoodCreateModel goodCreateModel, HttpPostedFileBase upload) { goodCreateModel.Date = DateTime.Now; Mapper.CreateMap <GoodCreateModel, 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 <GoodCreateModel, GoodDTO>(goodCreateModel); if (upload != null && upload.ContentLength > 0) { good.ImageType = upload.ContentType; using (var reader = new BinaryReader(upload.InputStream)) { good.Image = reader.ReadBytes(upload.ContentLength); } } return(good); }
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 IActionResult Get(int id) { try { CategoryDTO category = _categoryLogic.Get(id); return(Ok(category)); } catch (EntityNotExists fe) { return(NotFound(fe.MessageError())); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }