public async Task <IActionResult> Create(ProductBaseInputModel inputModel) { if (!this.ModelState.IsValid) { inputModel.Categories = this._categoryRepository.GetAll() .ToSelectList(category => category.Name, category => category.Id); return(this.View(inputModel)); } try { await this._productRepository.Create(inputModel); this.TempData.AddSerialized <Alert>("Alerts", new Alert(AlertType.Success, "Successfully created a new product.")); return(this.RedirectToAction(nameof(this.All))); } catch (ArgumentException e) { this.ModelState.AddModelError(string.Empty, e.Message); return(this.View(inputModel)); } }
public IActionResult Create() { var model = new ProductBaseInputModel { Categories = this._categoryRepository.GetAll() .ToSelectList(category => category.Name, category => category.Id) }; return(this.View(model)); }