Beispiel #1
0
        public IQueryable <preg_other_app> GetItemsByParams(preg_other_app data)
        {
            IQueryable <preg_other_app> result = connect.preg_other_app;

            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 == "name" && (int)propertyValue != 0)
                {
                    result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.name) > 0);
                }
                else if (propertyName == "google_play" && propertyValue != null)
                {
                    result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.google_play) > 0);
                }
                else if (propertyName == "app_store" && propertyValue != null)
                {
                    result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.app_store) > 0);
                }
                else if (propertyName == "time_created" && propertyValue != null)
                {
                    result = result.Where(c => c.time_created == (DateTime)(propertyValue));
                }
                else if (propertyName == "time_last_update" && propertyValue != null)
                {
                    result = result.Where(c => c.time_last_update == (DateTime)(propertyValue));
                }
            }
            return(result);
        }
Beispiel #2
0
        public HttpResponseMessage UpdateData(string id, preg_other_app dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_other_app()))
                {
                    preg_other_app other_app = new preg_other_app();
                    other_app = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (other_app == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.name != null)
                    {
                        other_app.name = dataUpdate.name;
                    }
                    if (dataUpdate.google_play != null)
                    {
                        other_app.google_play = dataUpdate.google_play;
                    }
                    if (dataUpdate.app_store != null)
                    {
                        other_app.app_store = dataUpdate.app_store;
                    }
                    if (dataUpdate.time_created != null)
                    {
                        other_app.time_created = dataUpdate.time_created;
                    }
                    if (dataUpdate.time_last_update != null)
                    {
                        other_app.time_last_update = dataUpdate.time_last_update;
                    }

                    dao.UpdateData(other_app);
                    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));
            }
        }
Beispiel #3
0
        public HttpResponseMessage Delete(string id)
        {
            try
            {
                preg_other_app 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));
            }
        }
Beispiel #4
0
 public HttpResponseMessage Post([FromBody] preg_other_app data)
 {
     try
     {
         if (!data.DeepEquals(new preg_other_app()))
         {
             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));
     }
 }
Beispiel #5
0
 public HttpResponseMessage Get([FromUri] preg_other_app data)
 {
     try
     {
         if (!data.DeepEquals(new preg_other_app()))
         {
             IEnumerable <preg_other_app> 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_other_app> 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));
     }
 }
Beispiel #6
0
 public void DeleteData(preg_other_app item)
 {
     connect.preg_other_app.Remove(item);
     connect.SaveChanges();
 }
Beispiel #7
0
 public void UpdateData(preg_other_app item)
 {
     connect.SaveChanges();
 }
Beispiel #8
0
 public void InsertData(preg_other_app item)
 {
     connect.preg_other_app.Add(item);
     connect.SaveChanges();
 }
Beispiel #9
0
 public HttpResponseMessage Put(string id, [FromBody] preg_other_app dataUpdate)
 {
     return(UpdateData(id, dataUpdate));
 }