Пример #1
0
 public HttpResponseMessage Get([FromUri] preg_faq_answer data)
 {
     try
     {
         IEnumerable <preg_faq_answer> result;
         if (!data.DeepEquals(new preg_faq_answer()))
         {
             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 Post([FromBody] preg_faq_answer data)
 {
     try
     {
         if (!data.DeepEquals(new preg_faq_answer()))
         {
             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));
     }
 }
Пример #3
0
        public HttpResponseMessage Put(string id, [FromBody] preg_faq_answer dataUpdate)
        {
            try
            {
                if (!dataUpdate.DeepEquals(new preg_faq_answer()))
                {
                    preg_faq_answer faq_answer = new preg_faq_answer();
                    faq_answer = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault();
                    if (faq_answer == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND));
                    }
                    if (dataUpdate.faq_id != 0)
                    {
                        faq_answer.faq_id = dataUpdate.faq_id;
                    }
                    if (dataUpdate.answer_content != null)
                    {
                        faq_answer.answer_content = dataUpdate.answer_content;
                    }

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