示例#1
0
        public HttpResponseMessage AddUser(UserModel userModel)
        {
            try
            {
                // אם הולידציה נכשלה:
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
                }

                if (logic.IsUserExists(userModel))
                {
                    List <PropErrors> error = new List <PropErrors>();

                    error.Add(new PropErrors()
                    {
                        property = "userName or password", errors = new List <string>()
                        {
                            "There is existing user with that userName or password"
                        }
                    });
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, error));
                }


                UserModel user = logic.AddUser(userModel);
                return(Request.CreateResponse(HttpStatusCode.Created, user));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public HttpResponseMessage AddFeedback(UserFeedbackModel userFeedbackModel)
        {
            try
            {
                // אם הולידציה נכשלה:
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
                }

                UserFeedbackModel userFeedback = logic.AddFeedback(userFeedbackModel);
                return(Request.CreateResponse(HttpStatusCode.Created, userFeedback));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public HttpResponseMessage AddGameResult(GameResultModel gameResultModel)
        {
            try
            {
                // אם הולידציה נכשלה:
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
                }

                GameResultModel gameResult = logic.AddGameResult(gameResultModel);
                return(Request.CreateResponse(HttpStatusCode.Created, gameResult));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
        public HttpResponseMessage AddFeedback(UserFeedbackModel feedbackmodel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
                }
                UserFeedbackModel feedback = logic.AddFeedback(feedbackmodel);
                feedback.username = userlogic.GetUserName(feedback.userid);

                return(Request.CreateResponse(HttpStatusCode.Created, feedback));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }