コード例 #1
0
        public IHttpActionResult AddUser(UserModel userModel)
        {
            try
            {
                // if bad information was sent:
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Content(HttpStatusCode.BadRequest, errorList));
                }

                // if an existed user tries to register (username & password):
                if (loginLogic.Login(userModel.username, userModel.password) != null)
                {
                    string error = "This user already exists in DB.";
                    return(Content(HttpStatusCode.Conflict, error));
                }

                UserModel um = usersLogic.AddUser(userModel);
                ModelState.Clear(); //? check it
                return(Content(HttpStatusCode.Created, um));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #2
0
        public IHttpActionResult Login(LoginModel loginModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Content(HttpStatusCode.BadRequest, errorList));
                }

                LoginModel returnedLoginModel = loginLogic.Login(loginModel.username, loginModel.password);

                // If the user doesn't exist in DB
                if (returnedLoginModel == null)
                {
                    string error = "Error Message: This user doesn't exist.";
                    return(Content(HttpStatusCode.NotFound, error));
                }

                return(Ok(returnedLoginModel));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #3
0
 public IHttpActionResult AddMessage(ContactUsMessageModel messageModel)
 {
     try
     {
         // if bad information was sent:
         if (!ModelState.IsValid)
         {
             List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
             return(Content(HttpStatusCode.BadRequest, errorList));
         }
         ContactUsMessageModel mm = messagesLogic.AddMessage(messageModel);
         return(Content(HttpStatusCode.Created, mm));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
コード例 #4
0
        public IHttpActionResult GetAllFeedbacks()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Content(HttpStatusCode.BadRequest, errorList));
                }

                List <FeedbackModel> feedbacks = feedbacksLogic.GetAllFeedbacks();
                return(Ok(feedbacks));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #5
0
        public IHttpActionResult AddFeedback(FeedbackModel feedbackModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Content(HttpStatusCode.BadRequest, errorList));
                }

                FeedbackModel fm = feedbacksLogic.AddFeedback(feedbackModel);
                return(Content(HttpStatusCode.Created, fm));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #6
0
        public IHttpActionResult GetAllResults(GameResultModel gameResultModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Content(HttpStatusCode.BadRequest, errorList));
                }

                List <GameResultModel> grm = gameResultsLogic.GetAllResults();
                return(Ok(grm));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #7
0
        public IHttpActionResult AddGameResult(GameResultModel gameResultModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Content(HttpStatusCode.BadRequest, errorList));
                }

                GameResultModel grm = gameResultsLogic.AddResult(gameResultModel);
                return(Content(HttpStatusCode.Created, grm));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
コード例 #8
0
        public HttpResponseMessage AddFeedback(FeedbackModel feedbackModel)
        {
            try
            {
                // if validation faild:
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
                }

                FeedbackModel fm = logic.AddFeedback(feedbackModel);
                return(Request.CreateResponse(HttpStatusCode.Created, fm));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }