public IActionResult Post([FromBody] AddModelDto dto) { try { _addModelCommand.Execute(dto); return(StatusCode(201, "Successfully added model.")); } catch (EntityAlreadyExistsException) { return(StatusCode(422, "An error has occured.")); } catch (Exception e) { return(StatusCode(500, e)); } }
public ActionResult Post([FromBody] ModelDto dto) { try { _add.Execute(dto); return(StatusCode(201)); } catch (EntityAlreadyExistsException e) { return(Conflict(e)); } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(500)); } }
public ActionResult Create(AddModelDto dto) { if (!ModelState.IsValid) { TempData["error"] = "Oopss, somethng went wrong."; RedirectToAction(nameof(Index)); } try { // TODO: Add insert logic here _addModel.Execute(dto); return(RedirectToAction(nameof(Index))); } catch (EntityAlreadyExistsException) { TempData["error"] = "Model with that name already exists."; } catch (Exception) { TempData["error"] = "An error has occurred."; } return(View()); }