public ActionResult Create(CategoryDto categoryDto) { if (!ModelState.IsValid) { TempData["error"] = "An error occured."; return(View()); } try { _createCategoryCommand.Execute(categoryDto); TempData["success"] = "Category created."; return(RedirectToAction(nameof(Index))); } catch (EntityAlreadyExistsException e) { TempData["error"] = e.Message; } catch (Exception e) { TempData["error"] = e.Message; } return(View()); }
public ActionResult Add(CreateCategoryDto request) { try { _createCategoryCommand.Execute(request); return(RedirectToAction("Index")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); } return(View()); }
public ActionResult Post([FromBody] CategoryDto categoryDto) { try { _createCategoryCommand.Execute(categoryDto); return(StatusCode(StatusCodes.Status201Created)); } catch (EntityAlreadyExistsException e) { return(Conflict(e.Message)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public IActionResult Post([FromForm] CategoryDto dto) { try { _createCategory.Execute(dto); return(Ok()); } catch (EntityAlreadyExistsException e) { return(Conflict(e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public IActionResult Create([FromBody] CreateCategoryDto viewModel) { if (string.IsNullOrEmpty(viewModel.Name)) { return(BadRequest("Name polje mora imate vrednost")); } try { _command.Execute(viewModel); return(StatusCode(201)); } catch (EntityNotFoundException e) { return(UnprocessableEntity(e.Message)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public IActionResult Create(CategoryDto categoryDto) { _createCategory.Execute(categoryDto); return(RedirectToAction("Create", "Product")); }