public bool DeleteReferenceData(int kick_result_id) { try { int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); PregnancyEntity connect = new PregnancyEntity(); IEnumerable <preg_kick_result_detail> kickResultDetailDel = connect.preg_kick_result_detail.Where(c => c.kick_result_id == kick_result_id); while (kickResultDetailDel.Count() > 0) { connect.preg_kick_result_detail.Remove(kickResultDetailDel.FirstOrDefault()); connect.SaveChanges(); } IEnumerable <preg_user_kick_history> userKickHistoryDel = connect.preg_user_kick_history.Where(c => c.user_id == user_id && c.kick_result_id == kick_result_id); while (userKickHistoryDel.Count() > 0) { connect.preg_user_kick_history.Remove(userKickHistoryDel.FirstOrDefault()); connect.SaveChanges(); } return(true); } catch (Exception ex) { return(false); } }
public void InsertData(preg_weekly_interact item) { try { connect.preg_weekly_interact.Add(item); connect.SaveChanges(); } catch (System.Exception ex) { throw ex; } }
public bool InsertData(preg_medical_package_test item) { try { connect.preg_medical_package_test.Add(item); connect.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool InsertData(preg_user_baby_name item) { IEnumerable <preg_user_baby_name> result = GetItemByParams(item); if (result.Count() > 0) { return(false); } else { connect.preg_user_baby_name.Add(item); connect.SaveChanges(); return(true); } }
public bool InsertData(preg_user_medical_service_package item) { IEnumerable <preg_user_medical_service_package> result = GetItemByParams(item); if (result.Count() > 0) { return(false); } else { connect.preg_user_medical_service_package.Add(item); connect.SaveChanges(); return(true); } }
public HttpResponseMessage Post([FromBody] preg_kick_result data) { try { if (!data.DeepEquals(new preg_kick_result())) { dao.InsertData(data); //Insert to UserKickHistories int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); preg_user_kick_history userKickHistory = new preg_user_kick_history() { user_id = user_id, kick_result_id = data.id }; using (PregnancyEntity connect = new PregnancyEntity()) { connect.preg_user_kick_history.Add(userKickHistory); connect.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.Created, data)); } 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 bool InsertData(preg_user item) { IEnumerable <preg_user> result = GetUsersByParams(new preg_user() { phone = item.phone, social_type_id = item.social_type_id }); if (result.Count() > 0) { return(false); } else { connect.preg_user.Add(item); connect.SaveChanges(); return(true); } }
public HttpResponseMessage DeleteAll() { try { PregnancyEntity connect = new PregnancyEntity(); int user_id = Convert.ToInt32(((ClaimsIdentity)(User.Identity)).FindFirst("id").Value); IQueryable <preg_user_kick_history> items = dao.GetListItem().Where(c => c.user_id == user_id); if (!items.Any()) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, SysConst.DATA_NOT_FOUND)); } while (items.Count() > 0) { int kickResultId = items.FirstOrDefault().kick_result_id; IQueryable <preg_kick_result_detail> kickResultDetailItem = connect.preg_kick_result_detail.Where(c => c.kick_result_id == kickResultId); while (kickResultDetailItem.Count() > 0) { connect.preg_kick_result_detail.Remove(kickResultDetailItem.FirstOrDefault()); connect.SaveChanges(); } dao.DeleteData(items.FirstOrDefault()); IQueryable <preg_kick_result> kickResultItem = connect.preg_kick_result.Where(c => c.id == kickResultId); while (kickResultItem.Count() > 0) { connect.preg_kick_result.Remove(kickResultItem.FirstOrDefault()); connect.SaveChanges(); } } 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 void InsertData(preg_setting item) { connect.preg_setting.Add(item); connect.SaveChanges(); }
public void InsertData(preg_help_category item) { connect.preg_help_category.Add(item); connect.SaveChanges(); }
public void InsertData(preg_kick_result item) { connect.preg_kick_result.Add(item); connect.SaveChanges(); }
public void InsertData(preg_image item) { connect.preg_image.Add(item); connect.SaveChanges(); }
public void InsertData(preg_my_birth_plan_item item) { connect.preg_my_birth_plan_item.Add(item); connect.SaveChanges(); }
public void InsertData(preg_appointment_type item) { connect.preg_appointment_type.Add(item); connect.SaveChanges(); }
public void InsertData(preg_other_app item) { connect.preg_other_app.Add(item); connect.SaveChanges(); }
public void InsertData(preg_pregnancy item) { connect.preg_pregnancy.Add(item); connect.SaveChanges(); }
public void InsertData(preg_hospital_bag_item item) { connect.preg_hospital_bag_item.Add(item); connect.SaveChanges(); }
public void InsertData(preg_daily item) { connect.preg_daily.Add(item); connect.SaveChanges(); }
/// <summary> /// Validate provided username and password when the grant_type is set to "password". /// </summary> /// <param name="context"></param> /// <returns></returns> public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { if (context.OwinContext.Request.Headers["Provider"] != null) { if (context.OwinContext.Request.Headers["Provider"].ToLower() == "facebook" && context.OwinContext.Request.Headers["access_token"] != null) { var accessToken = context.OwinContext.Request.Headers["access_token"]; var client = new RestClient("https://graph.facebook.com/"); var request = new RestRequest("me", Method.GET); request.AddQueryParameter("fields", "id,name,email,picture.width(2000).height(2000)"); request.AddQueryParameter("access_token", accessToken); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { var content = JObject.Parse(response.Content); var userInfo = new FacebookUserInfo() { id = content["id"].ToString() }; if (content["name"] != null) { userInfo.name = content["name"].ToString(); } if (content["email"] != null) { userInfo.email = content["email"].ToString(); } if (content["picture"]["data"]["url"] != null) { userInfo.avatar = content["picture"]["data"]["url"].ToString(); } PregnancyEntity connect = new PregnancyEntity(); preg_user user = connect.preg_user.Where(c => c.uid == userInfo.id && c.social_type_id == (int)SysConst.SocialTypes.facebook).FirstOrDefault(); if (user != null) { //user.email = userInfo.email; //user.first_name = userInfo.name; user.time_last_login = DateTime.Now; connect.SaveChanges(); } else { user = new preg_user(); user.uid = userInfo.id; user.email = userInfo.email; user.first_name = userInfo.name; user.avatar = userInfo.avatar; user.social_type_id = (int)SysConst.SocialTypes.facebook; user.time_created = DateTime.Now; connect.preg_user.Add(user); SysMethod.createAccountNop(user); connect.SaveChanges(); user = connect.preg_user.Where(c => c.uid == userInfo.id && c.social_type_id == (int)SysConst.SocialTypes.facebook).FirstOrDefault(); } preg_auth auth = connect.preg_auth.Where(c => c.user_id == user.id).FirstOrDefault(); if (auth == null) { auth = new preg_auth() { user_id = user.id }; connect.preg_auth.Add(auth); } auth.token = context.OwinContext.Request.Headers["access_token"]; connect.SaveChanges(); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.social.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.user.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.dev.ToString())); identity.AddClaim(new Claim("id", user.id.ToString())); context.Validated(identity); } else { context.SetError("Invalid grant", SysConst.LOGIN_SOCIAL_FAILED); return; } } else if (context.OwinContext.Request.Headers["Provider"].ToLower() == "google" && context.OwinContext.Request.Headers["access_token"] != null) { var accessToken = context.OwinContext.Request.Headers["access_token"]; var client = new RestClient("https://www.googleapis.com/oauth2/v3/"); var request = new RestRequest("tokeninfo", Method.GET); request.AddQueryParameter("id_token", accessToken); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { var content = JObject.Parse(response.Content); var userInfo = new GoogleUserInfo() { sub = content["sub"].ToString() }; if (content["name"] != null) { userInfo.name = content["name"].ToString(); } if (content["email"] != null) { userInfo.email = content["email"].ToString(); } if (content["picture"] != null) { userInfo.picture = content["picture"].ToString(); } if (content["given_name"] != null) { userInfo.given_name = content["given_name"].ToString(); } if (content["family_name"] != null) { userInfo.family_name = content["family_name"].ToString(); } PregnancyEntity connect = new PregnancyEntity(); preg_user user = connect.preg_user.Where(c => c.uid == userInfo.sub && c.social_type_id == (int)SysConst.SocialTypes.google).FirstOrDefault(); if (user != null) { //user.email = userInfo.email; //user.first_name = userInfo.name; //user.avatar = userInfo.picture; user.time_last_login = DateTime.Now; connect.SaveChanges(); } else { user = new preg_user(); user.uid = userInfo.sub; user.email = userInfo.email; user.first_name = userInfo.name; user.avatar = userInfo.picture; user.social_type_id = (int)SysConst.SocialTypes.google; user.time_created = DateTime.Now; connect.preg_user.Add(user); SysMethod.createAccountNop(user); connect.SaveChanges(); user = connect.preg_user.Where(c => c.uid == userInfo.sub && c.social_type_id == (int)SysConst.SocialTypes.google).FirstOrDefault(); } preg_auth auth = connect.preg_auth.Where(c => c.user_id == user.id).FirstOrDefault(); if (auth == null) { auth = new preg_auth() { user_id = user.id }; connect.preg_auth.Add(auth); } auth.token = context.OwinContext.Request.Headers["access_token"]; connect.SaveChanges(); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.social.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.user.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.dev.ToString())); identity.AddClaim(new Claim("id", user.id.ToString())); context.Validated(identity); } else { var client2 = new RestClient("https://www.googleapis.com/oauth2/v1/"); var request2 = new RestRequest("userinfo", Method.GET); request2.AddQueryParameter("alt", "json"); request2.AddQueryParameter("access_token", accessToken); var response2 = client.Execute(request2); if (response2.StatusCode == HttpStatusCode.OK) { var content = JObject.Parse(response2.Content); var userInfo = new GoogleUserInfo() { sub = content["sub"].ToString() }; if (content["name"] != null) { userInfo.name = content["name"].ToString(); } if (content["email"] != null) { userInfo.email = content["email"].ToString(); } if (content["picture"] != null) { userInfo.picture = content["picture"].ToString(); } if (content["given_name"] != null) { userInfo.given_name = content["given_name"].ToString(); } if (content["family_name"] != null) { userInfo.family_name = content["family_name"].ToString(); } PregnancyEntity connect = new PregnancyEntity(); preg_user user = connect.preg_user.Where(c => c.uid == userInfo.sub && c.social_type_id == (int)SysConst.SocialTypes.google).FirstOrDefault(); if (user != null) { //user.email = userInfo.email; //user.first_name = userInfo.name; //user.avatar = userInfo.picture; user.time_last_login = DateTime.Now; connect.SaveChanges(); } else { user = new preg_user(); user.uid = userInfo.sub; user.email = userInfo.email; user.first_name = userInfo.name; user.avatar = userInfo.picture; user.social_type_id = (int)SysConst.SocialTypes.google; user.time_created = DateTime.Now; connect.preg_user.Add(user); SysMethod.createAccountNop(user); connect.SaveChanges(); user = connect.preg_user.Where(c => c.uid == userInfo.sub && c.social_type_id == (int)SysConst.SocialTypes.google).FirstOrDefault(); } preg_auth auth = connect.preg_auth.Where(c => c.user_id == user.id).FirstOrDefault(); if (auth == null) { auth = new preg_auth() { user_id = user.id }; connect.preg_auth.Add(auth); } auth.token = context.OwinContext.Request.Headers["access_token"]; connect.SaveChanges(); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.social.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.user.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.dev.ToString())); identity.AddClaim(new Claim("id", user.id.ToString())); context.Validated(identity); } else { context.SetError("Invalid grant", SysConst.LOGIN_SOCIAL_FAILED); return; } } } } else if (context.UserName != null && context.Password != null) { var identity = new ClaimsIdentity(context.Options.AuthenticationType); PregnancyEntity connect = new PregnancyEntity(); UserDao dao = new UserDao(); //Check username & password string phone = context.UserName; string password = SysMethod.MD5Hash(context.Password); preg_user user = connect.preg_user.Where(c => c.phone == phone && c.password == password).FirstOrDefault(); if (user != null) { user.time_last_login = DateTime.Now; connect.SaveChanges(); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.dev.ToString())); identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.user.ToString())); identity.AddClaim(new Claim("id", user.id.ToString())); context.Validated(identity); } else if (context.UserName == "WSPadmin" && context.Password == "WSPadmin") { identity.AddClaim(new Claim(ClaimTypes.Role, SysConst.UserType.admin.ToString())); identity.AddClaim(new Claim("id", "0")); context.Validated(identity); } else { context.SetError("Invalid grant", SysConst.LOGIN_FAILED); return; } } }
public void InsertData(preg_shopping_item item) { connect.preg_shopping_item.Add(item); connect.SaveChanges(); }
public void InsertData(preg_guides item) { connect.preg_guides.Add(item); connect.SaveChanges(); }
public void InsertData(preg_customer_response item) { connect.preg_customer_response.Add(item); connect.SaveChanges(); }
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 InsertData(preg_medical_service_package item) { connect.preg_medical_service_package.Add(item); connect.SaveChanges(); }
public void InsertData(preg_baby_name item) { connect.preg_baby_name.Add(item); connect.SaveChanges(); }
public void InsertData(preg_medical_test item) { connect.preg_medical_test.Add(item); connect.SaveChanges(); }
public void InsertData(preg_auth item) { connect.preg_auth.Add(item); connect.SaveChanges(); }
public void InsertData(preg_faq_answer item) { connect.preg_faq_answer.Add(item); connect.SaveChanges(); }
public void InsertData(preg_question item) { connect.preg_question.Add(item); connect.SaveChanges(); }
public void InsertData(preg_my_weight item) { connect.preg_my_weight.Add(item); connect.SaveChanges(); }