public HttpResponseMessage UpdateData(string id, preg_size_guide dataUpdate) { try { if (!dataUpdate.DeepEquals(new preg_size_guide())) { preg_size_guide size_guide = new preg_size_guide(); size_guide = dao.GetItemByWeekID(Convert.ToInt32(id)).FirstOrDefault(); if (size_guide == null) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND); } if (dataUpdate.image != null) { size_guide.image = dataUpdate.image; } if (dataUpdate.title != null) { size_guide.title = dataUpdate.title; } if (dataUpdate.description != null) { size_guide.description = dataUpdate.description; } if (dataUpdate.week_id != null) { size_guide.week_id = dataUpdate.week_id; } if (dataUpdate.length != null) { size_guide.length = dataUpdate.length; } if (dataUpdate.weight != null) { size_guide.weight = dataUpdate.weight; } if (dataUpdate.type != null) { size_guide.type = dataUpdate.type; } dao.UpdateData(size_guide); 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 Post([FromBody]preg_size_guide data) { try { if (!data.DeepEquals(new preg_size_guide())) { 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 Get([FromUri]preg_size_guide data) { try { if (!data.DeepEquals(new preg_size_guide())) { IEnumerable<preg_size_guide> 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_size_guide> 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); } }