コード例 #1
0
 public IActionResult Post([FromBody] BlogArticle blogarticle)
 {
     try
     {
         if (blogarticle == null || !ModelState.IsValid)
         {
             return(BadRequest(ErrorCode.TitleAndContentRequired.ToString()));
         }
         bool itemExists = _repository.DoesItemExist(blogarticle.Id).Result;
         if (itemExists)
         {
             return(StatusCode(StatusCodes.Status409Conflict, ErrorCode.IDInUse.ToString()));
         }
         _repository.AddAsync(blogarticle);
     }
     catch (Exception)
     {
         return(BadRequest(ErrorCode.CouldNotCreateItem.ToString()));
     }
     return(Ok(blogarticle));
 }