public ActionResult AddNewModel(ModelViewModel model, HttpPostedFileBase uploadImage) { if (ModelState.IsValid) { if (uploadImage != null) { string writePath = Server.MapPath(@"~/Content/Images/Models/") + model.Name + ".jpg"; Image img = Image.FromStream(uploadImage.InputStream); img.Save(writePath); model.PhotoUrl = model.Name + ".jpg"; } model.BrandId = (int)TempData.Peek("BrandId"); try { modelService.AddModel(Mapper.Map <ModelViewModel, ModelDTO>(model)); } catch (ValidationException ex) { ViewBag.PropertyException = ex.Property; ViewBag.MessageException = ex.Message; ViewBag.BrandId = model.BrandId; return(View("ExceptionView")); } } return(RedirectToAction("Models", new RouteValueDictionary(new { controller = "Model", action = "Models", brandId = TempData["BrandId"] }))); }
public async Task <IActionResult> AddModel(AddModelDto newModel) { ServiceResponse <Model> response = await _modelService.AddModel(newModel); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public ActionResult <ModelVM> AddModel([FromBody] ModelDTO modelDTO) { var model = _mapper.Map <Model>(modelDTO); _modelService.AddModel(model); _modelService.SaveChanges(); _log.Save(User.Identity.Name, "Dodano model", GetType().Name); return(Ok()); }
public async Task <IActionResult> AddModel([FromBody] ModelDto model) { if (!ModelState.IsValid) { return(BadRequest()); } var newModel = _mapper.Map <Model>(model); await _modelService.AddModel(newModel); return(Ok(_mapper.Map <ModelDto>(newModel))); }