public async Task <IActionResult> Create([FromForm] ProductInputModel inputModel) { if (inputModel == null) { return(BadRequest()); } var product = inputModel.ToEntity(); if (null != inputModel.Photo) { string imagePath = await _fs.Create(inputModel.Photo.OpenReadStream(), FileTypes.ProductPhoto, _fs.CreateDefaultFileName(inputModel.Photo.FileName)); product.Photo = imagePath; } product = _store.Create(product); var outputModel = ProductOutputModel.FromEntity(product); return(CreatedAtRoute("ViewProduct", new { id = outputModel.Id }, outputModel)); }
public ActionResult <ProductOutputModel> Get(long id) { Product product = _store.GetById(id); if (null == product) { return(NoContent()); } return(ProductOutputModel.FromEntity(product)); }
// GET: Products/Details/5 public IActionResult Details(int?id) { Product product = FetchOrDefault(id); if (null == product) { return(NotFound()); } return(View(ProductOutputModel.FromEntity(product))); }
public IActionResult Create([FromForm] ProductInputModel inputModel) { if (!ModelState.IsValid) { return(View(inputModel)); } var product = inputModel.ToEntity(); product = _store.Create(product); var outputModel = ProductOutputModel.FromEntity(product); return(RedirectToAction(nameof(Index))); }
public IActionResult Create([FromBody] ProductInputModel inputModel) { if (inputModel == null) { return(BadRequest()); } var product = inputModel.ToEntity(); product = _store.Create(product); var outputModel = ProductOutputModel.FromEntity(product); var result = CreatedAtRoute("ViewProduct", new { id = outputModel.Id }, outputModel); return(result); }