예제 #1
0
 public HttpResponseMessage AddMessage(MessageModel messagemodel)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
         }
         MessageModel message = logic.AddMessage(messagemodel);
         return(Request.CreateResponse(HttpStatusCode.Created, message));
     }
     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 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));
            }
        }
예제 #3
0
 public HttpResponseMessage AddUser(UserModel userModel)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             List <PropErrors> errorList = ErrorExtractor.ExtractErrors(ModelState);
             return(Request.CreateResponse(HttpStatusCode.BadRequest, errorList));
         }
         if (logic.IsUsernameExist(userModel.username) == false)
         {
             UserModel user = logic.AddUser(userModel);
             return(Request.CreateResponse(HttpStatusCode.Created, user));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "user name taken"));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); // for DEV env
     }
 }