public HttpResponseMessage GetOneResult(int id)
        {
            try
            {
                GameResultModel result = logic.GetOneResult(id);
                result.fullname = userlogic.GetFullName(result.userid);
                result.username = userlogic.GetUserName(result.userid);

                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Пример #2
0
        public GameResultModel AddResult(GameResultModel gameResultModel)
        {
            GameResult result = new GameResult
            {
                UserID            = gameResultModel.userid,
                DatePlayed        = DateTime.Now,
                GameSessionLength = gameResultModel.gamesessionlength,
                StepsTaken        = gameResultModel.stepstaken
            };

            DB.GameResults.Add(result);
            DB.SaveChanges();



            gameResultModel.gameresultid = result.GameResultID;



            return(GetOneResult(result.GameResultID));
        }
        public HttpResponseMessage AddGameResult(GameResultModel gameresultmodel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
                }
                GameResultModel result = logic.AddResult(gameresultmodel);
                result.fullname = userlogic.GetFullName(result.userid);
                result.username = userlogic.GetUserName(result.userid);


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