public async Task <IActionResult> DeleteLink(string userID, int contactLinkID) { ContactLink thisCL = ((_context.ContactLinks.Where(i => (i.Users.Id == userID) && (i.ContactLinkID == contactLinkID)).FirstOrDefault())); _context.ContactLinks.Remove(thisCL); await _context.SaveChangesAsync(); var returnPath = "../Users/Edit/" + userID.ToString(); return(Redirect(returnPath)); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var cEmail = ContactEmail; UserObject contact = await _userManager.FindByEmailAsync(cEmail); if (contact == null) { contact = new UserObject { UserName = cEmail, Email = cEmail }; var result = await _userManager.CreateAsync(contact); if (!result.Succeeded) { throw new SystemException("could not create user"); } } else { // TODO inform uses that contact email is already in the db and what significance that might have for them } ContactLink contactLink = new ContactLink(); contactLink.Parent = UserID; // there is an edge case not covered if the user is deleted between get and post - even if it were valid now, the same could occur later as well - TODO need to handle that anyway contactLink.Child = contact.Id; // contact.Id; contactLink.Creation = DateTime.UtcNow; contactLink.LastUsed = DateTime.UtcNow; contactLink.Expires = Expiration; contactLink.Type = RelType; contactLink.Relationship = Relationship; contactLink.GivenNames = GivenNames; contactLink.FamilyName = FamilyNames; contactLink.Phones = Phones; contactLink.AlternateEmail = Emails; try { _context.contactLinks.Add(contactLink); await _context.SaveChangesAsync(); } catch { throw new SystemException("could not create contact"); // TODO duplicates or write errors should not happen - but we should deal with them in a more friendly way if they do } return(RedirectToPage("./Display")); // TODO make it possible to redirect to the page that brought us here }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } ContactLink = await _context.contactLinks.FirstOrDefaultAsync(m => m.Id == id); if (ContactLink == null) { return(NotFound()); } return(Page()); }
private void CreateUserLinks(string[] createdLinkLabels, string[] createdLinkUrls, User newUser) { if (createdLinkLabels != null) { for (var i = 0; i < createdLinkLabels.Length; i++) { ContactLink newContact = new ContactLink { ContactLinkLabel = createdLinkLabels[i], ContactLinkUrl = createdLinkUrls[i], Users = newUser }; _context.Add(newContact); } } }
static void Main(string[] args) { string connStr = "Server=(local);Database=EfShardingTpt;Integrated Security=true"; using (MyDbContext myDbContext = new MyDbContext(connStr)) { // Drop and recreate database Database.SetInitializer(new DropCreateDatabaseAlways <MyDbContext>()); } // Create ContactLinkCustomer using (MyDbContext myDbContext = new MyDbContext(connStr)) { ContactLinkCustomer clc = new ContactLinkCustomer { Contact_ID = Guid.Empty, Contact_Link_ID = Guid.Empty, Customer_ID = Guid.Empty, Tenant_ID = Guid.Parse("00000000-0000-0000-0000-100000000000") }; myDbContext.ContactLinkCustomers.Add(clc); myDbContext.SaveChanges(); } WriteTenantIds(connStr); // Update through subtype using (MyDbContext myDbContext = new MyDbContext(connStr)) { ContactLinkCustomer clc = myDbContext.ContactLinkCustomers.First(); clc.Tenant_ID = Guid.Parse("00000000-0000-0000-0000-200000000000"); myDbContext.SaveChanges(); } WriteTenantIds(connStr); // Update through supertype using (MyDbContext myDbContext = new MyDbContext(connStr)) { ContactLink cl = myDbContext.ContactLinks.First(); cl.Tenant_ID = Guid.Parse("00000000-0000-0000-0000-300000000000"); myDbContext.SaveChanges(); } WriteTenantIds(connStr); }
public async Task <IActionResult> OnGetAsync(string id) { if (id == null) { return(NotFound()); } var user = await _userManager.GetUserAsync(User); ContactLink cl = await _context.contactLinks.FirstOrDefaultAsync(m => m.Id == id); if (cl == null) { return(NotFound()); } if (ce == null) { ce = new ContactEdit(); } ce.Id = cl.Id; ce.ParentName = await _userManager.GetUserNameAsync(user); ce.Creation = cl.Creation; ce.FamilyName = cl.FamilyName; ce.GivenNames = cl.GivenNames; ce.LastUsed = cl.LastUsed; ce.Expires = cl.Expires; ce.Phones = cl.Phones; ce.AlternateEmail = cl.AlternateEmail; ce.Relationship = cl.Relationship; ce.RelType = cl.Type; ce.ChildEmail = "email not found"; UserObject child = await _userManager.FindByIdAsync(cl.Child); if (child != null) { ce.ChildEmail = child.Email; } return(Page()); }
private void CreateUserLinks(string[] createdLinkLabels, string[] createdLinkUrls, User newUser) { if (createdLinkLabels != null) { for (var i = 0; i < createdLinkLabels.Length; i++) { createdLinkUrls[i] = createdLinkUrls[i].ToLower(); if (!createdLinkUrls[i].Contains("constellation.citwdd.net") && !(createdLinkUrls[i].Contains("http://") || createdLinkUrls[i].Contains("https://"))) { createdLinkUrls[i] = "http://" + createdLinkUrls[i]; } ContactLink newContact = new ContactLink { ContactLinkLabel = createdLinkLabels[i], ContactLinkUrl = createdLinkUrls[i], Users = newUser }; _context.Add(newContact); } } }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } ContactLink cl = await _context.contactLinks.FirstOrDefaultAsync(m => m.Id == ce.Id); if (cl == null) { throw new Exception("could not load contack link"); } // verify that the contact is that of the signed in user! (Security Requirement to avoid attack against the db) bool bChanged = false; // The following are the only fields where a change will cause an update. if (ce.Phones != cl.Phones) { cl.Phones = ce.Phones; bChanged = true; } if (ce.AlternateEmail != cl.AlternateEmail) { cl.AlternateEmail = ce.AlternateEmail; bChanged = true; } if (ce.Relationship != cl.Relationship) { cl.Relationship = ce.Relationship; bChanged = true; } if (ce.RelType != cl.Type) { cl.Type = ce.RelType; bChanged = true; } if (ce.FamilyName != cl.FamilyName) { cl.FamilyName = ce.FamilyName; bChanged = true; } if (ce.GivenNames != cl.GivenNames) { cl.GivenNames = ce.GivenNames; bChanged = true; } if (ce.Expires != cl.Expires) { cl.Expires = ce.Expires; bChanged = true; } if (bChanged) { cl.LastUsed = DateTime.UtcNow; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactLinkExists(ce.Id)) { return(NotFound()); } else { throw; } } } return(RedirectToPage("./Index")); }
private ResidentInformation MapDetailsToResidentInformation(Person person, Address address, TenancyAgreement tenancyAgreement, ContactLink contactLink, int?contactKey) { var resident = person.ToDomain(); resident.UPRN = address?.UPRN; resident.ResidentAddress = address?.ToDomain(); resident.TenancyReference = tenancyAgreement?.TagRef.Trim(); resident.ContactKey = contactKey.ToString(); resident.TenureType = (tenancyAgreement == null) ? null : $"{tenancyAgreement.UhTenureTypeId.Trim()}: {tenancyAgreement.UhTenureType.Description.Trim()}"; if (contactLink == null) { return(resident); } var telephoneNumberForPerson = _UHContext .TelephoneNumbers.Where(t => t.ContactID == contactLink.ContactID).ToList(); var emailAddressForPerson = _UHContext.EmailAddresses.Where(c => c.ContactID == contactLink.ContactID).ToList(); AttachContactDetailsToPerson(resident, telephoneNumberForPerson, emailAddressForPerson); return(resident); }