public IHttpActionResult Post(ChatMessageAddRequest model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); // validation check on model } ItemResponse <int> response = new ItemResponse <int> { Item = _chatMessageService.Insert(model) // on is valid and success, set Item to hold response id }; return(Ok(response)); } catch (Exception ex) { int currentUser = _userService.GetCurrentUserId(); _appLogService.Insert(new AppLogAddRequest { AppLogTypeId = 1, Message = ex.Message, StackTrace = ex.StackTrace, Title = "Error in " + GetType().Name + " " + System.Reflection.MethodBase.GetCurrentMethod().Name, UserBaseId = currentUser }); return(BadRequest(ex.Message)); } }
public HttpResponseMessage Post(ChatMessageAddRequest model) { try { model.UserBaseId = _userService.GetCurrentUserId(); ItemResponse <int> response = new ItemResponse <int>(); response.Item = _chatMessageService.Insert(model); return(Request.CreateResponse(HttpStatusCode.OK, response)); } catch (Exception ex) { throw ex; } }