public IActionResult CreateBlog(BlogCommand blog) { try { if (blog != null) { BlogDto data = _mapper.Map <BlogDto>(blog); var iSuccess = _blogService.AddBlog(data); if (iSuccess) { SuccessModel.SuccessMessage = "Success"; SuccessModel.SuccessCode = "200"; return(Ok(SuccessModel)); } else { ErrorModel.ErrorMessage = "Update fail"; ErrorModel.ErrorCode = "400"; return(StatusCode(400, ErrorModel)); } } else { ErrorModel.ErrorMessage = "Data fail"; ErrorModel.ErrorCode = "400"; return(StatusCode(400, ErrorModel)); } } catch (Exception ex) { ErrorModel.ErrorMessage = ex.Message; ErrorModel.ErrorCode = "500"; return(StatusCode(500, ErrorModel)); } }
public async Task <Result <SuccessModel, ErrorModel> > CreateBlog(BlogCommand blog) //post { Uri url = new Uri(BaseUriUser, $"/Blog/CreateBlog"); Result <SuccessModel, ErrorModel> result = await PostMethodAsync <SuccessModel, ErrorModel>(url, blog); return(result); }