public HttpResponseMessage Post([FromBody] preg_page data) { try { if (!data.DeepEquals(new preg_page())) { 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)); } }
public HttpResponseMessage UpdateData(string id, preg_page dataUpdate) { try { if (!dataUpdate.DeepEquals(new preg_page())) { preg_page page = new preg_page(); page = dao.GetItemByID(Convert.ToInt32(id)).FirstOrDefault(); if (page == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } if (dataUpdate.title != null) { page.title = dataUpdate.title; } if (dataUpdate.content != null) { page.content = dataUpdate.content; } if (dataUpdate.page_image != null) { page.page_image = dataUpdate.page_image; } dao.UpdateData(page); 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)); } }
public HttpResponseMessage Get([FromUri] preg_page data) { try { if (!data.DeepEquals(new preg_page())) { IEnumerable <preg_page> 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_page> 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)); } }