コード例 #1
0
        public ActionResult Edit(int id, ReplacementItemModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }

                if (!_replacementItemsService.Update(id, model))
                {
                    ModelState.AddModelError("", "Cannot update item");
                    return(View(model));
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch (ItemNotFoundException)
            {
                return(NotFound(id));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", $"Something went wrong: {ex.Message}");
                return(View(model));
            }
        }