public async Task <JsonResult> Post([FromBody] SubItemVM vm) { try { var appUser = await GetAppUser(); SubItem subItem = Mapper.Map <SubItem>(vm); var addedSubItem = _repo.AddSubItem(appUser.Id, subItem); if (addedSubItem == null) { Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { message = "Unable to add subItem." })); } else { Response.StatusCode = (int)HttpStatusCode.OK; return(Json(Mapper.Map <SubItemVM>(addedSubItem))); } } catch (Exception ex) { _logger.LogError($"Exception while saving subitem: {ex}"); Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Json(new { message = "Unable to add subItem." })); } }