public IHttpActionResult CreateComments([FromBody] CommentsParametersCreate commentsParametersCreate) { if (commentsParametersCreate != null && ModelState.IsValid) { CommentsDTO commentsDTO = _gasstationsservice.CreateComments(commentsParametersCreate, out ReturnValues returnValues); if (!returnValues.Error) { return(Ok(new ResponseSuccess { Success = true, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message, Data = new { comments = commentsDTO, }, })); } return(Ok(new ResponseError { Success = false, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message })); } return(BadRequest(ModelState)); }
public CommentsDTO CreateComments(CommentsParametersCreate commentsParametersCreate, out ReturnValues returnValues) { #region Parameters Comment comments; CommentsDTO commentsDTO = null; returnValues = new ReturnValues(); #endregion try { comments = new Comment() { GasStaionID = Convert.ToInt32(commentsParametersCreate.GasStationID), RegistrationID = Convert.ToInt32(commentsParametersCreate.RegistrationID), Comment1 = commentsParametersCreate.Comment, CreatedOn = DateTime.Now }; _unitOfWork.CommentRepository.Insert(comments); _unitOfWork.PersistChanges(); commentsDTO = new CommentsDTO { ID = comments.ID.ToString(), GasStaionID = comments.GasStaionID.ToString(), RegistrationID = comments.RegistrationID.ToString(), Comment = comments.Comment1, CreatedOn = comments.CreatedOn.ToString(), }; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message + " inner --> " + ex.InnerException); } return(commentsDTO); }