예제 #1
0
 public HttpResponseMessage Get([FromUri] preg_kick_result data)
 {
     try
     {
         int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value);
         IQueryable <preg_kick_result> result;
         if (!data.DeepEquals(new preg_kick_result()))
         {
             result = dao.GetItemsByParams(data);
         }
         else
         {
             result = dao.GetListItem();
         }
         result = dao.FilterByUserID(result, user_id);
         if (result.Any())
         {
             return(Request.CreateResponse(HttpStatusCode.OK, dao.FilterJoin(result)));
         }
         else
         {
             HttpError err = new HttpError(SysConst.DATA_NOT_FOUND);
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, err));
         }
     }
     catch (Exception ex)
     {
         HttpError err = new HttpError(ex.Message);
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, err));
     }
 }
예제 #2
0
 public HttpResponseMessage Post([FromBody] preg_kick_result data)
 {
     try
     {
         if (!data.DeepEquals(new preg_kick_result()))
         {
             dao.InsertData(data);
             //Insert to UserKickHistories
             int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value);
             preg_user_kick_history userKickHistory = new preg_user_kick_history()
             {
                 user_id = user_id, kick_result_id = data.id
             };
             using (PregnancyEntity connect = new PregnancyEntity())
             {
                 connect.preg_user_kick_history.Add(userKickHistory);
                 connect.SaveChanges();
             }
             return(Request.CreateResponse(HttpStatusCode.Created, data));
         }
         else
         {
             HttpError err = new HttpError(SysConst.DATA_NOT_EMPTY);
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
         }
     }
     catch (Exception ex)
     {
         HttpError err = new HttpError(ex.Message);
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
     }
 }
예제 #3
0
        public HttpResponseMessage Put(string id, [FromBody] preg_kick_result dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_kick_result()))
                {
                    preg_kick_result kick_result = new preg_kick_result();
                    kick_result = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (kick_result == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.kick_date != null)
                    {
                        kick_result.kick_date = dataUpdate.kick_date;
                    }
                    if (dataUpdate.duration != null)
                    {
                        kick_result.duration = dataUpdate.duration;
                    }

                    dao.UpdateData(kick_result);
                    return(Request.CreateResponse(HttpStatusCode.Accepted, SysConst.DATA_UPDATE_SUCCESS));
                }
                else
                {
                    HttpError err = new HttpError(SysConst.DATA_NOT_EMPTY);
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
                }
            }
            catch (Exception ex)
            {
                HttpError err = new HttpError(ex.Message);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
            }
        }