Exemplo n.º 1
0
 public IActionResult Put(int id, [FromBody] GetModelDto dto)
 {
     try
     {
         dto.Id = id;
         _editModelCommand.Execute(dto);
         return(StatusCode(204));
     }
     catch
     {
         return(StatusCode(422));
     }
 }
Exemplo n.º 2
0
        public void Execute(GetModelDto request)
        {
            var model = Context.Models.Find(request.Id);

            if (model == null)
            {
                throw new EntityNotFoundException();
            }

            if (request.Name != model.Name && Context.Models.Any(m => m.Name == request.Name))
            {
                throw new EntityAlreadyExistsException();
            }

            model.Name           = request.Name;
            model.ManufacturerId = request.ManufacturerId;
            Context.SaveChanges();
        }
Exemplo n.º 3
0
 public ActionResult Edit(int id, GetModelDto dto)
 {
     if (!ModelState.IsValid)
     {
         TempData["error"] = "Ooops, something went wrong.";
         return(RedirectToAction(nameof(Index)));
     }
     try
     {
         // TODO: Add update logic here
         _editModel.Execute(dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityNotFoundException)
     {
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityAlreadyExistsException)
     {
         TempData["error"] = "Model with that name already exists.";
         return(View(dto));
     }
 }