public async Task <IActionResult> Upsert(Resident obj) { if (ModelState.IsValid) { if (obj.Id == 0) { if (await _reRepo.CreateAsync(SD.ResidentAPIPath, obj, HttpContext.Session.GetString("JWToken"))) { // Gets a new GUID for the contact form guid = Guid.NewGuid(); // Sends an email with all required information await _emailSender.SendEmailAsync("*****@*****.**", "Reference Number: " + guid, "<h2>Email: " + obj.PrimaryContact.Email + "</h2>" + "<br>" + "<h2>Your Application Was Successful!</h2>" + "<p>" + obj.PrimaryContact.FirstName + " " + obj.PrimaryContact.LastName + " will be contacted shortly for further instruction.</p>" + "<p>The account below has been created for the primary contact:</p>" + "<p>Username: "******"<br>" + "Password:"******"</p>" + "<p>You can access your account on https://admedtech.com/ </p>"); // Sends an email with all required information await _emailSender.SendEmailAsync(obj.PrimaryContact.Email, "Reference Number: " + guid, "<h2>Email: " + obj.PrimaryContact.Email + "</h2>" + "<br>" + "<h2>Your Application Was Successful!</h2>" + "<p>The account below has been created for the primary contact:</p>" + "<p>" + obj.PrimaryContact.FirstName + " " + obj.PrimaryContact.LastName + " will be contacted shortly for further instruction.</p>" + "<p>Username: "******"<br>" + "Password:"******"</p>" + "<p>You can access your account on https://admedtech.com/ </p>"); if (_application != null) { _application.Invisible = true; await _apRepo.UpdateAsync(SD.ApplicationAPIPath + _application.Id, _application, HttpContext.Session.GetString("JWToken")); } User user = new User() { FirstName = obj.PrimaryContact.FirstName, LastName = obj.PrimaryContact.LastName, Username = obj.PrimaryContact.Email, Password = guid.ToString(), Role = "Resident", ConfirmPassword = guid.ToString() }; await _accRepo.RegisterAsync(SD.AccountAPIPath + "register/", user); } } else { await PostUpdateResident(obj); } return(RedirectToAction(nameof(Index))); } return(View(obj)); }