public HttpResponseMessage GetOneGameResult(int id) { try { GameResultModel gameResult = logic.GetOneGameResult(id); return(Request.CreateResponse(HttpStatusCode.OK, gameResult)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } }
public GameResultModel AddGameResult(GameResultModel gameResultModel) { GameResult gameResult = new GameResult { UserID = gameResultModel.userID, StepsTaken = gameResultModel.stepsTaken, DatePlayed = gameResultModel.datePlayed, GameSessionLength = TimeSpan.FromMilliseconds(gameResultModel.gameSessionLength), }; GameResult result = DB.GameResults.Add(gameResult); DB.SaveChanges(); return(GetOneGameResult(result.GameResultID)); }
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)); } }