public HttpResponseMessage Post([FromBody] preg_appointment data) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); //Check if user already have pregnancy data preg_appointment checkExist = dao.GetItemsByParams(new preg_appointment() { user_id = user_id }).FirstOrDefault(); if (checkExist != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, SysConst.DATA_EXIST)); } if (!data.DeepEquals(new preg_appointment())) { 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 HttpResponseMessage Get([FromUri] preg_appointment data) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); IEnumerable <preg_appointment> result; if (!data.DeepEquals(new preg_appointment())) { data.user_id = user_id; result = dao.GetItemsByParams(data); } else { 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)); } }
public IQueryable <preg_appointment> GetItemsByParams(preg_appointment data) { IQueryable <preg_appointment> result = connect.preg_appointment; 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 == "name" && propertyValue != null) { result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.name) > 0); } else if (propertyName == "contact_name" && propertyValue != null) { result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.contact_name) > 0); } else if (propertyName == "profession_id" && propertyValue != null) { result = result.Where(c => c.profession_id == (int)(propertyValue)); } else if (propertyName == "appointment_date" && propertyValue != null) { result = result.Where(c => c.appointment_date == (DateTime)(propertyValue)); } else if (propertyName == "appointment_time" && propertyValue != null) { result = result.Where(c => c.appointment_time == (DateTime)(propertyValue)); } else if (propertyName == "my_weight_type_id" && propertyValue != null) { result = result.Where(c => c.my_weight_type_id == (int)(propertyValue)); } else if (propertyName == "weight_in_st" && propertyValue != null) { result = result.Where(c => c.weight_in_st == (double)(propertyValue)); } else if (propertyName == "sync_to_calendar" && propertyValue != null) { result = result.Where(c => c.sync_to_calendar == (int)(propertyValue)); } else if (propertyName == "note" && propertyValue != null) { result = result.Where(c => SqlFunctions.PatIndex("%" + propertyValue.ToString() + "%", c.note) > 0); } else if (propertyName == "user_id" && propertyValue != null) { result = result.Where(c => c.user_id == (int)(propertyValue)); } else if (propertyName == "appointment_type_id" && propertyValue != null) { result = result.Where(c => c.appointment_type_id == (int)(propertyValue)); } } return(result); }
public HttpResponseMessage Delete() { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); preg_appointment appointment = dao.GetItemsByParams(new preg_appointment() { user_id = user_id }).FirstOrDefault(); if (appointment == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } dao.DeleteData(appointment); 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 bool DeleteReferenceData(int user_id) { try { PregnancyEntity connect = new PregnancyEntity(); preg_user user = connect.preg_user.Where(c => c.id == user_id).FirstOrDefault(); while (user.preg_answer.Count() > 0) { connect.preg_answer.Remove(user.preg_answer.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_appointment.Count() > 0) { preg_appointment appointment = user.preg_appointment.FirstOrDefault(); while (appointment.preg_appointment_measurement.Count() > 0) { connect.preg_appointment_measurement.Remove(appointment.preg_appointment_measurement.FirstOrDefault()); connect.SaveChanges(); } connect.preg_appointment.Remove(user.preg_appointment.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_auth.Count() > 0) { connect.preg_auth.Remove(user.preg_auth.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_contact_us.Count() > 0) { connect.preg_contact_us.Remove(user.preg_contact_us.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_contraction.Count() > 0) { connect.preg_contraction.Remove(user.preg_contraction.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_customer_response.Count() > 0) { connect.preg_customer_response.Remove(user.preg_customer_response.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_customer_response1.Count() > 0) { connect.preg_customer_response.Remove(user.preg_customer_response1.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_daily_interact.Count() > 0) { connect.preg_daily_interact.Remove(user.preg_daily_interact.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_my_birth_plan.Count() > 0) { connect.preg_my_birth_plan.Remove(user.preg_my_birth_plan.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_my_birth_plan_item.Count() > 0) { connect.preg_my_birth_plan_item.Remove(user.preg_my_birth_plan_item.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_my_weight.Count() > 0) { connect.preg_my_weight.Remove(user.preg_my_weight.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_phone.Count() > 0) { connect.preg_phone.Remove(user.preg_phone.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_pregnancy.Count() > 0) { connect.preg_pregnancy.Remove(user.preg_pregnancy.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_profession.Count() > 0) { connect.preg_profession.Remove(user.preg_profession.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_question.Count() > 0) { connect.preg_question.Remove(user.preg_question.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_setting.Count() > 0) { connect.preg_setting.Remove(user.preg_setting.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_upgrade.Count() > 0) { connect.preg_upgrade.Remove(user.preg_upgrade.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_weekly_interact.Count() > 0) { connect.preg_weekly_interact.Remove(user.preg_weekly_interact.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_user_baby_name.Count() > 0) { connect.preg_user_baby_name.Remove(user.preg_user_baby_name.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_user_hospital_bag_item.Count() > 0) { connect.preg_user_hospital_bag_item.Remove(user.preg_user_hospital_bag_item.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_hospital_bag_item.Count() > 0) { connect.preg_hospital_bag_item.Remove(user.preg_hospital_bag_item.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_my_belly.Count() > 0) { connect.preg_my_belly.Remove(user.preg_my_belly.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_user_kick_history.Count() > 0) { connect.preg_user_kick_history.Remove(user.preg_user_kick_history.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_user_medical_service_package.Count() > 0) { connect.preg_user_medical_service_package.Remove(user.preg_user_medical_service_package.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_user_shopping_cart.Count() > 0) { connect.preg_user_shopping_cart.Remove(user.preg_user_shopping_cart.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_shopping_item.Count() > 0) { connect.preg_shopping_item.Remove(user.preg_shopping_item.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_user_todo.Count() > 0) { connect.preg_user_todo.Remove(user.preg_user_todo.FirstOrDefault()); connect.SaveChanges(); } while (user.preg_todo.Count() > 0) { connect.preg_todo.Remove(user.preg_todo.FirstOrDefault()); connect.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }
public void DeleteData(preg_appointment item) { connect.preg_appointment.Remove(item); connect.SaveChanges(); }
public void UpdateData(preg_appointment item) { connect.SaveChanges(); }
public void InsertData(preg_appointment item) { connect.preg_appointment.Add(item); connect.SaveChanges(); }
public HttpResponseMessage Put([FromBody] preg_appointment dataUpdate) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); if (!dataUpdate.DeepEquals(new preg_appointment())) { preg_appointment appointment = new preg_appointment(); appointment = dao.GetItemsByParams(new preg_appointment() { user_id = user_id }).FirstOrDefault(); if (appointment == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } if (dataUpdate.name != null) { appointment.name = dataUpdate.name; } if (dataUpdate.contact_name != null) { appointment.contact_name = dataUpdate.contact_name; } if (dataUpdate.profession_id != null) { appointment.profession_id = dataUpdate.profession_id; } if (dataUpdate.appointment_date != null) { appointment.appointment_date = dataUpdate.appointment_date; } if (dataUpdate.appointment_time != null) { appointment.appointment_time = dataUpdate.appointment_time; } if (dataUpdate.my_weight_type_id != null) { appointment.my_weight_type_id = dataUpdate.my_weight_type_id; } if (dataUpdate.weight_in_st != null) { appointment.weight_in_st = dataUpdate.weight_in_st; } if (dataUpdate.sync_to_calendar != null) { appointment.sync_to_calendar = dataUpdate.sync_to_calendar; } if (dataUpdate.note != null) { appointment.note = dataUpdate.note; } if (dataUpdate.appointment_type_id != null) { appointment.appointment_type_id = dataUpdate.appointment_type_id; } dao.UpdateData(appointment); 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)); } }