Exemple #1
0
 public HttpResponseMessage Get([FromUri] preg_help_category data)
 {
     try
     {
         IEnumerable <preg_help_category> result;
         if (!data.DeepEquals(new preg_help_category()))
         {
             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));
     }
 }
Exemple #2
0
 public HttpResponseMessage Post([FromBody] preg_help_category data)
 {
     try
     {
         if (!data.DeepEquals(new preg_help_category()))
         {
             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));
     }
 }
Exemple #3
0
        public HttpResponseMessage UpdateData(string id, preg_help_category dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_help_category()))
                {
                    preg_help_category HelpCategory = new preg_help_category();
                    HelpCategory = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (HelpCategory == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.name != null)
                    {
                        HelpCategory.name = dataUpdate.name;
                    }
                    if (dataUpdate.highline_image != null)
                    {
                        HelpCategory.highline_image = dataUpdate.highline_image;
                    }
                    if (dataUpdate.order != null)
                    {
                        HelpCategory.order = dataUpdate.order;
                    }

                    dao.UpdateData(HelpCategory);
                    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));
            }
        }