public static CompleteProfile GetCompleteProfile(BasicProfile profile) { CompleteProfile result = new CompleteProfile(); BasicProfile basicProfile = new BasicProfile(); result.BasicProfile=basicProfile; using (var db = new FHNWPrototypeDB()) { if (profile.ReferenceType == AccountType.UserAccount) { var ua = db.UserAccounts .Include("User") .Include("OrganizationAccount.Organization") .FirstOrDefault(x => x.Key == profile.ReferenceKey); result.BasicProfile.ReferenceKey = ua.Key; result.BasicProfile.ReferenceType = AccountType.UserAccount; result.FullName = ua.User.FirstName + " " + ua.User.LastName; result.Description1 = ua.OrganizationAccount.Name; result.Description2 = ua.OrganizationAccount.Organization.Name; } if (profile.ReferenceType == AccountType.OrganizationAccount) { var oa = db.OrganizationAccounts .Include("Organization") .FirstOrDefault(x => x.Key == profile.ReferenceKey); result.BasicProfile.ReferenceKey = oa.Key; result.BasicProfile.ReferenceType = AccountType.OrganizationAccount; result.FullName = oa.Name; result.Description1 = oa.Description; result.Description2 = oa.Organization.Name; } if (profile.ReferenceType == AccountType.Group ) { var g = db.Groups.FirstOrDefault(x => x.Key == profile.ReferenceKey); result.BasicProfile.ReferenceKey = g.Key; result.BasicProfile.ReferenceType = AccountType.Group; result.FullName = g.Name; result.Description1 = g.Description; result.Description2 = g.Description; } if (profile.ReferenceType == AccountType.Alliance ) { var al = db.Groups.FirstOrDefault(x => x.Key == profile.ReferenceKey); result.BasicProfile.ReferenceKey = al.Key; result.BasicProfile.ReferenceType = AccountType.Alliance; result.FullName = al.Name; result.Description1 = al.Description; result.Description2 = al.Description; } } return result; }
public ActionResult Login(LoginSystemAccountView model, string returnUrl) { if (ModelState.IsValid) { SystemAuthenticationTokenViewModel tokenVM = securityService.AttemptAuthentication(model.Email, model.Password); if (tokenVM.IsAuthenticated) { FormsAuthentication.SetAuthCookie(model.Email, false); Session.Clear(); CompleteProfile myNewProfile = new CompleteProfile { BasicProfile = new BasicProfile { ReferenceKey = new Guid(tokenVM.MyProfile.BasicProfile.ReferenceKey), ReferenceType = tokenVM.MyProfile.BasicProfile.AccountType }, FullName = tokenVM.MyProfile.FullName, Description1 = tokenVM.MyProfile.Description1, Description2 = tokenVM.MyProfile.Description2 }; if (Session["myProfile"] == null) { Session.Add("myProfile",myNewProfile ); } else { Session["myProfile"] = myNewProfile; } if (tokenVM.MyProfile.BasicProfile.AccountType == AccountType.OrganizationAccount) { return RedirectToAction("Index", "OrganizationAccounts"); } if (tokenVM.MyProfile.BasicProfile.AccountType == AccountType.UserAccount) { return RedirectToAction("Index", "UserAccounts"); } ModelState.AddModelError("", "Something happened, we can't let you go on =-/ "); return View(model); } else { ModelState.AddModelError("", "The email or password provided is incorrect."); return View(model); } } else { ModelState.AddModelError("", "The email or password provided is incorrect."); return View(model); } }
public static SystemAuthenticationToken AttemptAuthentication(string email, string password) { if (UserAlreadyExists(email)) { SystemAccount result = null; using (var db = new FHNWPrototypeDB()) { result = db.SystemAccounts .Include("Holder") .Single(x => x.Email == email); if (result.Password == password) { SystemAuthenticationToken token = new SystemAuthenticationToken(); token.IsAuthenticated = true; CompleteProfile completeProfile = new CompleteProfile(); completeProfile.BasicProfile = result.Holder; switch(result.Holder.ReferenceType) { case AccountType.UserAccount : var ua = db.UserAccounts .Include("User") .Include("OrganizationAccount.Organization") .SingleOrDefault(x => x.Key == result.Holder.ReferenceKey); completeProfile.FullName = ua.User.FirstName + " " + ua.User.LastName; completeProfile.Description1 = ua.OrganizationAccount.Name; completeProfile.Description2 = ua.OrganizationAccount.Organization.Name; break; case AccountType.OrganizationAccount: var oa = db.OrganizationAccounts .Include("Organization") .SingleOrDefault(x => x.Key == result.Holder.ReferenceKey); completeProfile.FullName = oa.Name; completeProfile.Description1 = oa.Description; completeProfile.Description2 = oa.Organization.Name; break; } token.MyProfile = completeProfile; token.Email = email; token.LastSuccesfulLogin = DateTime.Now; //register the new check //result.LastCheck = DateTime.Now; //db.SaveChanges(); return token; } else { SystemAuthenticationToken token = new SystemAuthenticationToken() { Email = email, IsAuthenticated = false }; return token; } } } else { SystemAuthenticationToken token = new SystemAuthenticationToken() { Email = email, IsAuthenticated = false }; return token; } }
//private FHNWPrototypeDB db = null; //public SecurityRepository() //{ // //db = new FHNWPrototypeDB(); //} public static CompleteProfile GetCompleteProfileFromUserEmail(string userEmail) { CompleteProfile result = new CompleteProfile(); result.BasicProfile = new BasicProfile(); using (var db = new FHNWPrototypeDB()) { BasicProfile profile = db.SystemAccounts.Include("Holder").FirstOrDefault(x => x.Email == userEmail).Holder; if (profile.ReferenceType == AccountType.UserAccount) { var ua = db.UserAccounts .Include("User") .Include("OrganizationAccount.Organization") .FirstOrDefault(x => x.Key == profile.ReferenceKey); result.BasicProfile.ReferenceKey = ua.Key; result.BasicProfile.ReferenceType = AccountType.UserAccount; result.FullName = ua.User.FirstName + " " + ua.User.LastName; result.Description1 = ua.OrganizationAccount.Name; result.Description2 = ua.OrganizationAccount.Organization.Name; } if (profile.ReferenceType == AccountType.OrganizationAccount) { var oa = db.OrganizationAccounts .Include("Organization") .FirstOrDefault(x => x.Key == profile.ReferenceKey); result.BasicProfile.ReferenceKey = oa.Key; result.BasicProfile.ReferenceType = AccountType.OrganizationAccount; result.FullName = oa.Name; result.Description1 = oa.Description; result.Description2 = oa.Organization.Name; } return result; } }
protected void getCompleteProfileInformation() { string newLine = "<br/>"; string col_start = "<td>", col_end = "</td>", row_start = "<tr>", row_end = "</tr>"; connect.Open(); SqlCommand cmd = connect.CreateCommand(); cmd.CommandText = "select userId from Users where loginId = '" + loginId + "' "; string userId = cmd.ExecuteScalar().ToString(); CompleteProfile completeProfile = new CompleteProfile(userId, profileId); string completeProfileId = completeProfile.Id; if (!string.IsNullOrWhiteSpace(completeProfileId)) { string onDialysis = completeProfile.OnDialysis; string kidneyDisease = completeProfile.KidneyDisease; string issueDate = completeProfile.IssueStartDate; string bloodType = completeProfile.BloodType; string address = completeProfile.Address + newLine + " " + completeProfile.City + ", " + completeProfile.State + " " + completeProfile.Zip; int counter = 0; string row = ""; row += row_start + col_start + col_end + col_start + col_end + row_end; row += row_start + col_start + col_end + col_start + col_end + row_end; row += row_start + col_start + "Complete Profile Information: " + col_end + row_end; if (!string.IsNullOrWhiteSpace(onDialysis)) { row += row_start + col_start + "On dialysis: " + col_end + col_start + onDialysis + col_end + row_end; } if (!string.IsNullOrWhiteSpace(kidneyDisease)) { row += row_start + col_start + "Kidney disease stage: " + col_end + col_start + kidneyDisease + col_end + row_end; } if (!string.IsNullOrWhiteSpace(issueDate)) { row += row_start + col_start + "Health issue started on: " + col_end + col_start + issueDate + col_end + row_end; } if (!string.IsNullOrWhiteSpace(bloodType)) { row += row_start + col_start + "Blood type: " + col_end + col_start + bloodType + col_end + row_end; } row += row_start + col_start + "Address: " + col_end + col_start + address + col_end + row_end; List <Insurance> insurances = completeProfile.Insurances; if (insurances.Count > 0) { row += row_start + col_start + "Insurances: " + col_end + col_start + col_end + row_end; } foreach (Insurance ins in insurances) { row += row_start + col_start + "Insurance #:" + col_end + col_start + ++counter + col_end + row_end; row += row_start + col_start + "Member ID:" + col_end + col_start + ins.MemberId + col_end + row_end; row += row_start + col_start + "Group ID:" + col_end + col_start + ins.GroupId + col_end + row_end; row += row_start + col_start + "Insurance name: " + col_end + col_start + ins.CompanyName + col_end + row_end; row += row_start + col_start + "Insurance phone1 : " + col_end + col_start + ins.Phone1 + col_end + row_end; row += row_start + col_start + "Insurance phone2 : " + col_end + col_start + ins.Phone2 + col_end + row_end; row += row_start + col_start + "Insurance email: " + col_end + col_start + ins.Phone2 + col_end + row_end; row += row_start + col_start + "Insurance address: " + col_end + col_start + ins.Address + newLine + ins.City + ", " + ins.State + " " + ins.Zip + newLine + ins.Country + col_end + row_end; } ArrayList allergies = completeProfile.Allergies; if (allergies.Count > 0) { row += row_start + col_start + "Allergies: " + col_end + col_start + col_end + row_end; } counter = 0; foreach (var a in allergies) { row += row_start + col_start + col_end + col_start + ++counter + ". " + a.ToString() + col_end + row_end; } ArrayList majorDiagnoses = completeProfile.MajorDiagnoses; if (majorDiagnoses.Count > 0) { row += row_start + col_start + "Major diagnoses: " + col_end + col_start + col_end + row_end; } counter = 0; foreach (var a in majorDiagnoses) { row += row_start + col_start + col_end + col_start + ++counter + ". " + a.ToString() + col_end + row_end; } ArrayList pastHealthConditions = completeProfile.PastHealthConditions; if (pastHealthConditions.Count > 0) { row += row_start + col_start + "Past health conditions: " + col_end + col_start + col_end + row_end; } counter = 0; foreach (var a in pastHealthConditions) { row += row_start + col_start + "" + col_end + col_start + ++counter + ". " + a.ToString() + col_end + row_end; } List <EmailObject> emails = completeProfile.Emails; if (emails.Count > 0) { row += row_start + col_start + "Emails: " + col_end + col_start + col_end + row_end; } counter = 0; foreach (EmailObject e in emails) { row += row_start + col_start + "" + col_end + col_start + ++counter + ". Email Address: " + e.EmailAddress; if (e.IsDefault == 1) { row += " (default)" + col_end + row_end; } else { row += col_end + row_end; } } List <Phone> phones = completeProfile.Phones; if (phones.Count > 0) { row += row_start + col_start + "Phone numbers: " + col_end + col_start + col_end + row_end; } counter = 0; foreach (Phone e in phones) { row += row_start + col_start + "" + col_end + col_start + ++counter + ". Phone number: " + e.PhoneNumber; if (e.IsDefault == 1) { row += " (default)" + col_end + row_end; } else { row += col_end + row_end; } } List <EmergencyContact> emergnecyContacts = completeProfile.EmergencyContacts; if (emergnecyContacts.Count > 0) { row += row_start + col_start + "Emergency contacts: " + col_end + col_start + col_end + row_end; } counter = 0; foreach (EmergencyContact e in emergnecyContacts) { row += row_start + col_start + "Contact #:" + col_end + col_start + ++counter + col_end + row_end; row += row_start + col_start + "Name: " + col_end + col_start + e.Firstname + " " + e.Lastname + col_end + row_end; row += row_start + col_start + "Phone 1: " + col_end + col_start + e.Phone1 + col_end + row_end; row += row_start + col_start + "Phone 2: " + col_end + col_start + e.Phone2 + col_end + row_end; row += row_start + col_start + "Phone 3: " + col_end + col_start + e.Phone3 + col_end + row_end; row += row_start + col_start + "Email: " + col_end + col_start + e.Email + col_end + row_end; row += row_start + col_start + "Address: " + col_end + col_start + e.Address + newLine + e.City + ", " + e.State + " " + e.Zip + newLine + e.Country + col_end + row_end; } List <PastPatientID> pastPatientIds = completeProfile.PastPatientIds; if (pastPatientIds.Count > 0) { row += row_start + col_start + "Past patient IDs: " + col_end + col_start + col_end + row_end; } counter = 0; int treatment_count = 0; foreach (PastPatientID p in pastPatientIds) { //row += row_start + col_start + "" + col_end + col_start + "" + col_end + row_end; row += row_start + col_start + "Medical Record Number: " + col_end + col_start + p.MRN + col_end + row_end; List <Treatment> treatments = completeProfile.Treatments; string str_treatments = ""; if (treatments.Count > 0) { str_treatments = "Treatments: " + newLine; } foreach (Treatment t in treatments) { if (t.PastPatientId.Equals(p.ID)) { row += row_start + col_start + "Treatment #: " + col_end + col_start + ++treatment_count + col_end + row_end; row += row_start + col_start + "Physician name: " + col_end + col_start + t.PhysicianFirstName + " " + t.PhysicianLastName + col_end + row_end; row += row_start + col_start + "Treatment started on: " + col_end + col_start + t.StartDate + col_end + row_end; row += row_start + col_start + "Hospital name: " + col_end + col_start + t.HospitalName + col_end + row_end; row += row_start + col_start + "Hospital address: " + col_end + col_start + t.HospitalAddress + newLine + t.HospitalCity + ", " + t.HospitalState + " " + t.HospitalZip + newLine + t.HospitalCountry + col_end + row_end; } } } lblRow.Text += row; } connect.Close(); }
// private FHNWPrototypeDB db = null; //public OrganizationAccountRepository() //{ // //db = FHNWSimulationDBContext.Current; // // db = new FHNWPrototypeDB(); //} public static CompleteProfile GetOrganizationAccountProfileByEmployeeUserAccountKey(Guid key) { CompleteProfile result = new CompleteProfile(); using (var db = new FHNWPrototypeDB()) { var org = db.UserAccounts .Include("OrganizationAccount") .FirstOrDefault(x => x.Key == key) .OrganizationAccount; result.BasicProfile = new BasicProfile { ReferenceKey=org.Key, ReferenceType= AccountType.OrganizationAccount }; result.FullName = org.Name; result.Description1 = org.Description; result.Description2 = org.Description; } return result; }
public static CompleteProfile GetGroupSuggestionByBasicProfile(string referenceKey) { var _address = "http://ef1ead3b4.hosted.neo4j.org:7968"; var _host = "ef1ead3b4.hosted.neo4j.org:7968"; var _content = "application/json"; var _authorization = "Basic NmI5YzY4M2VkOmI2MzZjMjgxOA=="; RestClient client = new RestClient(_address); CompleteProfile profile = null; List<Node> result = new List<Node>(); var request = new RestRequest(); request.Method = Method.POST; request.RequestFormat = DataFormat.Json; request.Resource = "/db/data/cypher"; //request.AddHeader("Content-Length", requestText.Length.ToString()); request.AddHeader("Host", _host); request.AddHeader("Accept", _content); request.AddHeader("Content-Type", _content); request.AddHeader("Authorization", _authorization); CypherQuery query = new CypherQuery(); query.query = "START origin=node(" + "1" + ") " + "MATCH origin-[:is_known_for]->tag, " + "tag<-[:is_known_for]-colleague, " + "colleague-[:is_group_member_of]-group " + "WHERE NOT (group<-[:is_group_member_of]-origin) " + "RETURN DISTINCT id(group) as Id, group.Key? as Key, group.Name? as Name " + "LIMIT 1"; request.AddBody(query); var response = client.Execute<CypherQueryResults>(request); var thisColumns = response.Data.columns; var thisData = response.Data.data; foreach (var l in thisData) { result.Add(new Node { Id = Int32.Parse(l[0]), Key = l[1], Name = l[2] }); } if (result.Count > 0) { profile = new CompleteProfile { BasicProfile = new BasicProfile { ReferenceKey = new Guid(result[0].Key), ReferenceType = AccountType.Group }, FullName = result[0].Name, Description1 = "", Description2 = "" }; } return profile; }
public static CompleteProfile GetWorkContactSuggestionByBasicProfile(string referenceKey) { var _address = "http://ef1ead3b4.hosted.neo4j.org:7968"; var _host = "ef1ead3b4.hosted.neo4j.org:7968"; var _content = "application/json"; var _authorization = "Basic NmI5YzY4M2VkOmI2MzZjMjgxOA=="; RestClient client = new RestClient(_address); CompleteProfile profile = null; List<Node> result = new List<Node>(); var request = new RestRequest(); request.Method = Method.POST; request.RequestFormat = DataFormat.Json; request.Resource = "/db/data/cypher"; //request.AddHeader("Content-Length", requestText.Length.ToString()); request.AddHeader("Host", _host); request.AddHeader("Accept", _content); request.AddHeader("Content-Type", _content); request.AddHeader("Authorization", _authorization); CypherQuery query = new CypherQuery(); query.query = "START origin=node(" + "1" + ") MATCH coworker-[:works_at]->company<-[:works_at]-origin " + "RETURN id(coworker) as Id, coworker.Key as Key, coworker.Name as Name " + "LIMIT 1"; //query.query = "START origin=node(" + "1" + ") MATCH origin-[:has_downstream_friend|has_upstream_friend*1..3]-my_partner, " + // "my_partner-[:is_known_for]->tag," + " coworker-[:works_at]->company<-[:works_at]-origin, " + // "my_coworkers_partner-[:has_downstream_friend|has_upstream_friend*1..3]-coworker, " + // "tag<-[:is_known_for]-my_coworkers_partner " + // "RETURN id(coworker) as Id, coworker.Key as Key, coworker.Name as Name " + // "LIMIT 1"; request.AddBody(query); var response = client.Execute<CypherQueryResults>(request); var thisColumns = response.Data.columns; var thisData = response.Data.data; foreach (var l in thisData) { result.Add(new Node { Id = Int32.Parse(l[0]), Key = l[1], Name = l[2] }); } if (result.Count > 0) { profile = new CompleteProfile { BasicProfile = new BasicProfile { ReferenceKey = new Guid(result[0].Key), ReferenceType = AccountType.UserAccount }, FullName = result[0].Name, Description1 = "", Description2 = "" }; } return profile; }