public IHttpActionResult PostOrder([FromBody] GadgetViewModel vm) { Gadget domain = null; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } domain = _mapper.Map <GadgetViewModel, Gadget>(vm); _gadgetService.CreateGadget(domain); _gadgetService.SaveGadget(); return(Ok(domain)); }
public async Task <IActionResult> Create(GadgetFormViewModel newGadget, ICollection <IFormFile> files) { if (newGadget != null && newGadget.File != null) { var gadget = Mapper.Map <GadgetFormViewModel, Gadget>(newGadget); gadgetService.CreateGadget(gadget); string gadgetPicture = System.IO.Path.GetFileName(newGadget.File); var uploads = System.IO.Path.Combine(_environment.WebRootPath, gadgetPicture); foreach (var file in files) { if (file.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } } } //newGadget.File.SaveAs(path); gadgetService.SaveGadget(); } var category = categoryService.GetCategory(newGadget.GadgetCategory); return(RedirectToAction("Index", new { category = category.Name })); }
public ActionResult Create(GadgetFormViewModel newGadget) { if (newGadget?.File != null) { var gadget = Mapper.Map <GadgetFormViewModel, Gadget>(newGadget); _gadgetService.CreateGadget(gadget); var gadgetPicture = System.IO.Path.GetFileName(newGadget.File.FileName); var path = System.IO.Path.Combine(Server.MapPath("~/images/"), gadgetPicture); newGadget.File.SaveAs(path); _gadgetService.SaveGadget(); } var category = _categoryService.GetCategory(newGadget.GadgetCategory); return(RedirectToAction("Index", new { category = category.Name })); }
public ActionResult Create(GadgetFormViewModel newGadget) { if (newGadget != null && newGadget.File != null) { var gadget = Mapper.Map <GadgetFormViewModel, Gadget>(newGadget); gadgetService.CreateGadget(gadget); string gadgetPicture = System.IO.Path.GetFileName(newGadget.File.FileName); //string path = System.IO.Path.Combine(Server.MapPath("~/images/"), gadgetPicture); //string path = System.IO.Path.Combine(Server.MapPath("~"), gadgetPicture); string path = @"C:\Users\px04148\Pictures\Prueba\" + gadgetPicture; newGadget.File.SaveAs(path); gadgetService.SaveGadget(); } var category = categoryService.GetCategory(newGadget.GadgetCategory); return(RedirectToAction("Index", new { category = category.Name })); }