private async Task<List<UserRegistration>> ImportUsers(OrgUserRegistration orgUserReg) { List<UserRegistration> userErrors = new List<UserRegistration>(); using (var db = new StationCADDb()) { // Loop thru.... foreach (UserRegistration item in orgUserReg.Users) { User user = null; try { // 1. Check to see if the user exists user = db.Users.Include("Profile").Where(x => x.Email == item.Email).FirstOrDefault(); // 1b. if not, CreateAsync() for User if (user == null) { user = new User { Id = Guid.NewGuid().ToString(), UserName = item.Email, Email = item.Email }; DateTime now = DateTime.Now; user.Profile = new UserProfile { FirstName = item.FirstName, LastName = item.LastName, CreateUser = "", CreateDate = now, LastUpdateUser = "", LastUpdateDate = now }; var result = await UserManager.CreateAsync(user, "P@ssword1"); if (!result.Succeeded) { userErrors.Add(item); break; } } // add user-org-affiliation OrganizationUserAffiliation uoa = new OrganizationUserAffiliation(); uoa.CurrentOrganization = orgUserReg.Organization; uoa.Role = OrganizationUserRole.User; uoa.Status = OrganizationUserStatus.Active; user.Profile.OrganizationAffiliations = new List<OrganizationUserAffiliation>(); user.Profile.OrganizationAffiliations.Add(uoa); await db.SaveChangesAsync(); } catch(Exception ex) { string msg = string.Format("", ""); base.LogException("", ex); userErrors.Add(item); break; } // 3. Create Email confirmation // 3a. If !emailConfirmed, create emailConfirmToken and send email if (!user.EmailConfirmed) { string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); string body = string.Format("{1}, {0}{0} You have been added as a user to {2}. Please confirm your account by clicking <a href=\"{3}\">here</a>. You will be required to choose a new password. {0}{0} Thanks, {0}{0} The StationCAD Team", Environment.NewLine, user.Profile.FirstName, orgUserReg.Organization.Name, callbackUrl); await UserManager.SendEmailAsync(user.Id, "StationCAD - Activate your account", body); } // 3b. Just send email letting them know they have been added to the org else { string body = string.Format("{1}, {0}{0} You have been added as a user to {2}. {0}{0} Thanks, {0}{0} The StationCAD Team", Environment.NewLine, user.Profile.FirstName, orgUserReg.Organization.Name); await UserManager.SendEmailAsync(user.Id, "StationCAD - You are part of a new Organization!", body); } } } return userErrors; }
public SMSEmailNotification GetSMSEmailNotification(OrganizationUserAffiliation userOrgAffiliation) { SMSEmailNotification smsEmail = new SMSEmailNotification(); smsEmail.MobileNumber = userOrgAffiliation.CurrentUserProfile.MobileDevices.First().MobileNumber; smsEmail.Carrier = userOrgAffiliation.CurrentUserProfile.MobileDevices.First().Carrier; smsEmail.MessageBody = GetShortNotificationBody(); smsEmail.OrganizationName = userOrgAffiliation.CurrentOrganization.Name; return smsEmail; }
public EmailNotification GetEmailNotification(OrganizationUserAffiliation userOrgAffiliation) { EmailNotification email = new EmailNotification(); email.Recipient = userOrgAffiliation.CurrentUserProfile.NotificationEmail; email.MessageSubject = string.Format("{0} - Incident: {1}", userOrgAffiliation.CurrentOrganization.Name, this.IncidentTypeCode); email.MessageBody = GetShortNotificationBody(); email.OrganizationName = userOrgAffiliation.CurrentOrganization.Name; return email; }
public List<IncidentNotification> GetNotifications(OrganizationUserAffiliation userOrgAffiliation) { List<IncidentNotification> results = new List<IncidentNotification>(); if (userOrgAffiliation.CurrentUserProfile.NotifcationPushMobile != null) results.Add(GetPushNotification()); return results; }
public void TestDispatchEventParsing() { string tag = "CC51-FWFC"; using (var db = new StationCADDb()) { string data; using (StreamReader sr = new StreamReader(@"TestData\UnitDispatchReport-F16001716.htm")) { data = sr.ReadToEnd(); } DispatchManager dispMgr = new DispatchManager(); Organization org = db.Organizations.Where(x => x.Tag == tag).FirstOrDefault(); if (org == null) { org = new Organization(); org.Name = "First West Chester Fire Company"; org.Status = OrganizationStatus.Active; org.Type = OrganizationType.Fire; org.Tag = tag; org.ContactEmail = "*****@*****.**"; org.ContactPhone = "610.883.3253"; db.Organizations.Add(org); try { db.SaveChanges(); } catch (Exception ex) { ex.ToString(); } } // Add UserProfile string email = "*****@*****.**"; User user; UserProfile usrp; user = db.Users .Include("Profile") .Include("Profile.OrganizationAffiliations") .Include("Profile.MobileDevices") .Where(w => w.Email == email) .FirstOrDefault(); if (user == null) { user = new User { Id = Guid.NewGuid().ToString(), UserName = email, Email = email }; usrp = new UserProfile(); usrp.FirstName = string.Format("FirstName_{0}", DateTime.Now.Ticks); usrp.LastName = string.Format("LastName_{0}", DateTime.Now.Ticks); usrp.AccountEmail = email; usrp.IdentificationNumber = DateTime.Now.Ticks.ToString(); //usrp.UserName = string.Format("{0}.{1}", usrp.FirstName, usrp.LastName); usrp.OrganizationAffiliations = new List<OrganizationUserAffiliation>(); usrp.OrganizationAffiliations.Add(new OrganizationUserAffiliation { Status = OrganizationUserStatus.Active, Role = OrganizationUserRole.User }); usrp.NotificationEmail = email; usrp.MobileDevices = new List<UserMobileDevice>(); usrp.MobileDevices.Add(new UserMobileDevice { Carrier = MobileCarrier.ATT, EnableSMS = true, MobileNumber = "6108833253" }); user.Profile = usrp; user.Profile.OrganizationAffiliations = new List<OrganizationUserAffiliation>(); OrganizationUserAffiliation uoa = new OrganizationUserAffiliation(); uoa.CurrentOrganization = org; uoa.Role = OrganizationUserRole.User; uoa.Status = OrganizationUserStatus.Active; user.Profile.OrganizationAffiliations.Add(uoa); db.Users.Add(user); } //usr2 = db.UserProfiles // .Include("OrganizationAffiliations")b // .Include("MobileDevices") // .Where(w => w.NotificationEmail == "*****@*****.**") // .FirstOrDefault(); //if (usr2 == null) //{ // usr2 = new UserProfile(); // usr2.FirstName = "Michael"; // usr2.LastName = "Lam"; // usr2.IdentificationNumber = DateTime.Now.Ticks.ToString(); //// usr2.UserName = string.Format("{0}.{1}", usr2.FirstName, usr2.LastName); // usr2.OrganizationAffiliations = new List<UserOrganizationAffiliation>(); // usr2.OrganizationAffiliations.Add(new UserOrganizationAffiliation { Status = OrganizationUserStatus.Active, Role = OrganizationUserRole.User }); // usr2.NotificationEmail = "*****@*****.**"; // usr2.MobileDevices = new List<UserMobileDevice>(); // usr2.MobileDevices.Add(new UserMobileDevice { Carrier = MobileCarrier.ATT, EnableSMS = true, MobileNumber = "6108833253" }); // db.UserProfiles.Add(usr2); //} db.SaveChanges(); dispMgr.ProcessEvent(org, data, DispatchManager.MessageType.Html); //db.UserProfiles.Remove(usrp); //db.SaveChanges(); } }