public HttpResponseMessage Put(string shopping_item_id, [FromBody] preg_user_shopping_cart dataUpdate) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); if (!dataUpdate.DeepEquals(new preg_user_shopping_cart())) { preg_user_shopping_cart user = new preg_user_shopping_cart(); user = dao.GetItemByID(user_id, Convert.ToInt32(shopping_item_id)).FirstOrDefault(); if (user == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } if (dataUpdate.status != null) { user.status = dataUpdate.status; } dao.UpdateData(user); 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_user_shopping_cart data) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); if (!data.DeepEquals(new preg_user_shopping_cart())) { data.user_id = user_id; IEnumerable <preg_user_shopping_cart> result = dao.GetItemByParams(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_user_shopping_cart> result = dao.GetListItem().Where(c => c.user_id == user_id); 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)); } }