示例#1
0
 public HttpResponseMessage Get([FromUri] preg_gender data)
 {
     try
     {
         IEnumerable <preg_gender> result;
         if (!data.DeepEquals(new preg_gender()))
         {
             result = dao.GetItemsByParams(data);
         }
         else
         {
             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));
     }
 }
示例#2
0
        public HttpResponseMessage Put(string id, [FromBody] preg_gender dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_gender()))
                {
                    preg_gender gender = new preg_gender();
                    gender = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (gender == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.gender != null)
                    {
                        gender.gender = dataUpdate.gender;
                    }

                    dao.UpdateData(gender);
                    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));
            }
        }
示例#3
0
 public HttpResponseMessage Delete(string id)
 {
     try
     {
         preg_gender gender = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
         if (gender == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
         }
         dao.DeleteData(gender);
         return(Request.CreateResponse(HttpStatusCode.Accepted, SysConst.DATA_DELETE_SUCCESS));
     }
     catch (Exception ex)
     {
         HttpError err = new HttpError(ex.Message);
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err));
     }
 }
示例#4
0
        public IQueryable <preg_gender> GetItemsByParams(preg_gender data)
        {
            IQueryable <preg_gender> result = connect.preg_gender;

            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 == "gender" && propertyValue != null)
                {
                    result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.gender) > 0);
                }
            }
            return(result);
        }
示例#5
0
 public HttpResponseMessage Post([FromBody] preg_gender data)
 {
     try
     {
         if (!data.DeepEquals(new preg_gender()))
         {
             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));
     }
 }
示例#6
0
 public HttpResponseMessage Get(string id)
 {
     try
     {
         preg_gender data = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
         if (data != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, data));
         }
         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));
     }
 }
示例#7
0
 public void DeleteData(preg_gender item)
 {
     connect.preg_gender.Remove(item);
     connect.SaveChanges();
 }
示例#8
0
 public void UpdateData(preg_gender item)
 {
     connect.SaveChanges();
 }
示例#9
0
 public void InsertData(preg_gender item)
 {
     connect.preg_gender.Add(item);
     connect.SaveChanges();
 }