Esempio n. 1
0
        public IQueryable <preg_notification> GetItemsByParams(preg_notification data)
        {
            IQueryable <preg_notification> result = connect.preg_notification;

            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 == "week_id" && (int)propertyValue != 0)
                {
                    result = result.Where(c => c.week_id == (int)(propertyValue));
                }
                else if (propertyName == "title" && propertyValue != null)
                {
                    result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.title) > 0);
                }
                else if (propertyName == "content" && propertyValue != null)
                {
                    result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.content) > 0);
                }
                else if (propertyName == "time_created" && propertyValue != null)
                {
                    result = result.Where(c => c.time_created == (DateTime)(propertyValue));
                }
                else if (propertyName == "time_last_push" && propertyValue != null)
                {
                    result = result.Where(c => c.time_last_push == (DateTime)(propertyValue));
                }
            }
            return(result);
        }
Esempio n. 2
0
        public HttpResponseMessage UpdateData(string id, preg_notification dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_notification()))
                {
                    preg_notification page = new preg_notification();
                    page = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (page == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.title != null)
                    {
                        page.title = dataUpdate.title;
                    }
                    if (dataUpdate.content != null)
                    {
                        page.content = dataUpdate.content;
                    }
                    if (dataUpdate.time_created != null)
                    {
                        page.time_created = dataUpdate.time_created;
                    }
                    if (dataUpdate.time_last_push != null)
                    {
                        page.time_last_push = dataUpdate.time_last_push;
                    }

                    dao.UpdateData(page);
                    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));
            }
        }
Esempio n. 3
0
        public HttpResponseMessage Delete(string id)
        {
            try
            {
                preg_notification item = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                if (item == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                }

                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));
            }
        }
Esempio n. 4
0
 public HttpResponseMessage Post([FromBody] preg_notification data)
 {
     try
     {
         if (!data.DeepEquals(new preg_notification()))
         {
             data.time_created = DateTime.Now;
             dao.InsertData(data);
             return(Request.CreateResponse(HttpStatusCode.Created, SysConst.DATA_INSERT_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));
     }
 }
Esempio n. 5
0
 public HttpResponseMessage Get([FromUri] preg_notification data)
 {
     try
     {
         if (!data.DeepEquals(new preg_notification()))
         {
             IEnumerable <preg_notification> result = dao.GetItemsByParams(data);
             if (result.Count() > 0)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, result));
             }
             else
             {
                 HttpError err = new HttpError(SysConst.DATA_NOT_FOUND);
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, err));
             }
         }
         else
         {
             IEnumerable <preg_notification> result = dao.GetListItem();
             if (result.Count() > 0)
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, 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));
     }
 }
Esempio n. 6
0
 public HttpResponseMessage Put(string id, [FromBody] preg_notification dataUpdate)
 {
     return(UpdateData(id, dataUpdate));
 }
Esempio n. 7
0
 public void DeleteData(preg_notification item)
 {
     connect.preg_notification.Remove(item);
     connect.SaveChanges();
 }
Esempio n. 8
0
 public void UpdateData(preg_notification item)
 {
     connect.SaveChanges();
 }
Esempio n. 9
0
 public void InsertData(preg_notification item)
 {
     connect.preg_notification.Add(item);
     connect.SaveChanges();
 }