コード例 #1
0
 public HttpResponseMessage Get([FromUri] preg_image data)
 {
     try
     {
         IEnumerable <preg_image> result;
         if (!data.DeepEquals(new preg_image()))
         {
             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 UpdateData(string week_id, string image_type_id, preg_image dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_image()))
                {
                    preg_image image = new preg_image();
                    image = dao.GetItemsByParams(new preg_image()
                    {
                        week_id = Convert.ToInt32(week_id), image_type_id = Convert.ToInt32(image_type_id)
                    }).FirstOrDefault();
                    if (image == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.image_type_id != null)
                    {
                        image.image_type_id = dataUpdate.image_type_id;
                    }
                    if (dataUpdate.image != null)
                    {
                        image.image = dataUpdate.image;
                    }
                    if (dataUpdate.week_id != null)
                    {
                        image.week_id = dataUpdate.week_id;
                    }

                    dao.UpdateData(image);
                    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 Post([FromBody] preg_image data)
 {
     try
     {
         if (!data.DeepEquals(new preg_image()))
         {
             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));
     }
 }