public IActionResult Edit(int id, [FromForm] CampaignInputModel inputModel) { if (inputModel == null) { return(NotFound()); } if (!ModelState.IsValid) { ViewData["ProductId"] = new SelectList(_productStore.List(), "Id", "Name", inputModel.ProductId); return(View(inputModel.ToEntity())); } int campaignId = id; if (!_productStore.Exists(inputModel.ProductId)) { ModelState.AddModelError("Product", $"Product '{inputModel.ProductId}' does not exists."); return(BadRequest(ModelState)); } try { var campaign = _service.GetById(campaignId); if (null == campaign) { return(NotFound()); } campaign.Name = inputModel.Name; campaign.Description = inputModel.Description; campaign.End = inputModel.End; campaign.Start = inputModel.Start; campaign.ProductId = inputModel.ProductId; _service.Update(campaign); campaignId = campaign.Id; } catch (DbUpdateConcurrencyException) { if (!_service.Exists(campaignId)) { return(NotFound()); } throw; } return(RedirectToAction(nameof(Index))); }