コード例 #1
0
        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());
        }
コード例 #2
0
 public ActionResult Add(CreateCategoryDto request)
 {
     try
     {
         _createCategoryCommand.Execute(request);
         return(RedirectToAction("Index"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError(string.Empty, ex.Message);
     }
     return(View());
 }
コード例 #3
0
 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));
     }
 }
コード例 #4
0
 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));
     }
 }
コード例 #5
0
        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));
            }
        }
コード例 #6
0
 public IActionResult Create(CategoryDto categoryDto)
 {
     _createCategory.Execute(categoryDto);
     return(RedirectToAction("Create", "Product"));
 }