Exemple #1
0
 public IActionResult Post([FromBody] AddManufacturerDto dto)
 {
     try
     {
         _addManufacturerCommand.Execute(dto);
         return(StatusCode(201, "Successfully added manufacturer."));
     }
     catch
     {
         return(StatusCode(422, "An error has occured"));
     }
 }
 public ActionResult Create(AddManufacturerDto dto)
 {
     if (!ModelState.IsValid)
     {
         TempData["error"] = "Ooops, something went wrong.";
         RedirectToAction(nameof(Index));
     }
     try
     {
         // TODO: Add insert logic here
         _addManufacturer.Execute(dto);
         return(RedirectToAction(nameof(Index)));
     }
     catch (EntityAlreadyExistsException)
     {
         TempData["error"] = "Manufacturer with that name already exists.";
     }
     catch (Exception)
     {
         TempData["error"] = "An error has occurred.";
     }
     return(View());
 }