public HttpResponseMessage Post([FromBody] preg_my_birth_plan_item data) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); if (!data.DeepEquals(new preg_my_birth_plan_item())) { if (data.custom_item_by_user_id != null) { data.custom_item_by_user_id = user_id; } 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 IQueryable <preg_my_birth_plan_item> GetItemsByParams(preg_my_birth_plan_item data) { IQueryable <preg_my_birth_plan_item> result = connect.preg_my_birth_plan_item; for (int i = 0; i < data.GetType().GetProperties().ToList().Count(); i++) { string propertyName = data.GetType().GetProperties().ToList()[i].Name; var propertyValue = data.GetType().GetProperty(propertyName).GetValue(data, null); if (propertyName == "id" && (int)(propertyValue) != 0) { result = result.Where(c => c.id == (int)(propertyValue)); } else if (propertyName == "my_birth_plan_type_id" && propertyValue != null) { result = result.Where(c => c.my_birth_plan_type_id == (int)(propertyValue)); } else if (propertyName == "item_content" && propertyValue != null) { result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.item_content) > 0); } else if (propertyName == "custom_item_by_user_id" && propertyValue != null) { result = result.Where(c => c.custom_item_by_user_id == (int)(propertyValue)); } } return(result); }
public HttpResponseMessage Get([FromUri] preg_my_birth_plan_item data) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); IEnumerable <preg_my_birth_plan_item> result; if (!data.DeepEquals(new preg_my_birth_plan_item())) { result = dao.GetItemsByParams(data).Where(c => c.custom_item_by_user_id == null || c.custom_item_by_user_id == user_id); } else { result = dao.GetListItem().Where(c => c.custom_item_by_user_id == null || c.custom_item_by_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)); } }
public HttpResponseMessage Delete(string id) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); preg_my_birth_plan_item item = dao.GetItemByID(Convert.ToInt32(id)).Where(c => c.custom_item_by_user_id == null || c.custom_item_by_user_id == user_id).FirstOrDefault(); if (item == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } dao.DeleteData(item); return(Request.CreateResponse(HttpStatusCode.Accepted, SysConst.DATA_DELETE_SUCCESS)); } catch (Exception ex) { HttpError err = new HttpError(ex.Message); return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, err)); } }
public HttpResponseMessage Put(string id, [FromBody] preg_my_birth_plan_item dataUpdate) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); if (!dataUpdate.DeepEquals(new preg_my_birth_plan_item())) { preg_my_birth_plan_item my_birth_plan_item = new preg_my_birth_plan_item(); my_birth_plan_item = dao.GetItemByID(Convert.ToInt32(id)).Where(c => c.custom_item_by_user_id == null || c.custom_item_by_user_id == user_id).FirstOrDefault(); if (my_birth_plan_item == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } if (dataUpdate.my_birth_plan_type_id != null) { my_birth_plan_item.my_birth_plan_type_id = dataUpdate.my_birth_plan_type_id; } if (dataUpdate.item_content != null) { my_birth_plan_item.item_content = dataUpdate.item_content; } if (dataUpdate.custom_item_by_user_id != null) { my_birth_plan_item.custom_item_by_user_id = user_id; } dao.UpdateData(my_birth_plan_item); 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(string id) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); preg_my_birth_plan_item data = dao.GetItemByID(Convert.ToInt32(id)).Where(c => c.custom_item_by_user_id == null || c.custom_item_by_user_id == user_id).FirstOrDefault(); if (data != null) { return(Request.CreateResponse(HttpStatusCode.OK, data)); } 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)); } }
public HttpResponseMessage Post([FromBody] preg_my_birth_plan data) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); if (data.my_birth_plan_item_id != 0) { //Check exist preg_my_birth_plan checkExist = dao.GetItemByID(user_id, data.my_birth_plan_item_id).FirstOrDefault(); if (checkExist != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, SysConst.DATA_EXIST)); } //Check My Birth Plan Item Exist using (PregnancyEntity connect = new PregnancyEntity()) { preg_my_birth_plan_item checkMyBPIExist = connect.preg_my_birth_plan_item.Where(c => c.id == data.my_birth_plan_item_id).FirstOrDefault(); if (checkMyBPIExist == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } } data.user_id = user_id; 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 void DeleteData(preg_my_birth_plan_item item) { connect.preg_my_birth_plan_item.Remove(item); connect.SaveChanges(); }
public void UpdateData(preg_my_birth_plan_item item) { connect.SaveChanges(); }
public void InsertData(preg_my_birth_plan_item item) { connect.preg_my_birth_plan_item.Add(item); connect.SaveChanges(); }