public IHttpActionResult DeleteCommentsByID([FromBody] CommentsParametersDelete commentsParametersDelete) { if (commentsParametersDelete != null && ModelState.IsValid) { CommentsDTO commentsDTO = _gasstationsservice.DeleteCommentsByID(commentsParametersDelete, out ReturnValues returnValues); if (!returnValues.Error) { return(Ok(new ResponseSuccess { Success = true, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message, Data = new { CommentsDeletdID = commentsDTO.ID } })); } return(Ok(new ResponseError { Success = false, Status = Convert.ToInt32(returnValues.Code), Message = returnValues.Message })); } return(BadRequest(ModelState)); }
public CommentsDTO DeleteCommentsByID(CommentsParametersDelete commentsParametersDelete, out ReturnValues returnValues) { #region Parameters Comment comments; CommentsDTO commentsDTO = null; returnValues = new ReturnValues(); int ID = Convert.ToInt32(commentsParametersDelete.ID); int registration = Convert.ToInt32(commentsParametersDelete.RegistrationID); int gasstation = Convert.ToInt32(commentsParametersDelete.GasStationID); #endregion try { comments = _unitOfWork.CommentRepository.Get(row => row.ID == ID && row.GasStaionID == gasstation && row.RegistrationID == registration); if (comments == null) { returnValues.SetReturnValues(true, ErrorCodes.NotFound, Utils.GetEnumDescription(ErrorCodes.NotFound)); return(commentsDTO); } _unitOfWork.CommentRepository.Delete(comments); _unitOfWork.PersistChanges(); commentsDTO = new CommentsDTO { ID = comments.ID.ToString(), }; returnValues.SetReturnValues(false, ErrorCodes.Ok, Utils.GetEnumDescription(ErrorCodes.Ok)); } catch (Exception ex) { returnValues.SetReturnValues(true, ErrorCodes.InternalError, ex.Message); } return(commentsDTO); }