コード例 #1
0
        public ActionResult Create(HashtagDto hashtagDto)
        {
            if (!ModelState.IsValid)
            {
                TempData["error"] = "An error occured.";
                return(View());
            }

            try
            {
                _createHashtagCommand.Execute(hashtagDto);
                TempData["success"] = "Hashtag 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 Post([FromBody] HashtagDto hashtagDto)
 {
     try
     {
         _createHashtagCommand.Execute(hashtagDto);
         return(StatusCode(StatusCodes.Status201Created));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception e)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, e.Message));
     }
 }