Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 3
0
        public HttpResponseMessage Delete(string id)
        {
            try
            {
                //Delete reference
                using (PregnancyEntity connect = new PregnancyEntity())
                {
                    preg_kick_result item = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (item == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (!DeleteReferenceData(Convert.ToInt32(id)))
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, SysConst.DATA_DELETE_FAIL));
                    }

                    dao.DeleteData(item);
                    return(Request.CreateResponse(HttpStatusCode.Accepted, SysConst.DATA_DELETE_SUCCESS));
                }
            }
            catch (Exception ex)
            {
                HttpError err = new HttpError(ex.Message);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
            }
        }
 public HttpResponseMessage Post([FromBody] preg_user_kick_history data)
 {
     try
     {
         int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value);
         if (data.kick_result_id != 0)
         {
             data.user_id = user_id;
             //Check exist
             preg_user_kick_history checkExist = dao.GetItemByParams(new preg_user_kick_history()
             {
                 user_id = data.user_id, kick_result_id = data.kick_result_id
             }).FirstOrDefault();
             if (checkExist != null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, SysConst.DATA_EXIST));
             }
             //Check kick result exist
             using (PregnancyEntity connect = new PregnancyEntity())
             {
                 preg_kick_result checkKickExist = connect.preg_kick_result.Where(c => c.id == data.kick_result_id).FirstOrDefault();
                 if (checkKickExist == null)
                 {
                     return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                 }
             }
             if (dao.InsertData(data))
             {
                 return(Request.CreateResponse(HttpStatusCode.Created, SysConst.DATA_INSERT_SUCCESS));
             }
             else
             {
                 HttpError err = new HttpError(SysConst.DATA_EXIST);
                 return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
             }
         }
         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));
     }
 }
Exemplo n.º 5
0
        public IQueryable <preg_kick_result> GetItemsByParams(preg_kick_result data)
        {
            IQueryable <preg_kick_result> result = connect.preg_kick_result;

            for (int i = 0; i < data.GetType().GetProperties().ToList().Count(); i++)
            {
                string propertyName  = data.GetType().GetProperties().ToList()[i].Name;
                var    propertyValue = data.GetType().GetProperty(propertyName).GetValue(data, null);
                if (propertyName == "id" && (int)(propertyValue) != 0)
                {
                    result = result.Where(c => c.id == (int)(propertyValue));
                }
                else if (propertyName == "kick_date" && propertyValue != null)
                {
                    result = result.Where(c => c.kick_date == (DateTime)(propertyValue));
                }
                else if (propertyName == "duration" && propertyValue != null)
                {
                    result = result.Where(c => c.duration == (float)(propertyValue));
                }
            }
            return(result);
        }
Exemplo n.º 6
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));
            }
        }
Exemplo n.º 7
0
 public void DeleteData(preg_kick_result item)
 {
     connect.preg_kick_result.Remove(item);
     connect.SaveChanges();
 }
Exemplo n.º 8
0
 public void UpdateData(preg_kick_result item)
 {
     connect.SaveChanges();
 }
Exemplo n.º 9
0
 public void InsertData(preg_kick_result item)
 {
     connect.preg_kick_result.Add(item);
     connect.SaveChanges();
 }