/// <summary> /// The update subscribe UI. /// </summary> /// <param name="selectedValue"> /// The selected value. /// </param> private void UpdateSubscribeUi(UserNotificationSetting selectedValue) { var showSubscribe = !(selectedValue is UserNotificationSetting.AllTopics or UserNotificationSetting.NoNotification); this.SubscribeHolder.Visible = showSubscribe; }
public async Task <string> Update(UserNotificationSetting notificationSetting) { try { var response = await ClientService.PostDataAsync(notificationSetting, ControllerName, "postsettings"); if (response != null) { Task <string> jsonTask = response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject(jsonTask.Result); if (jsonTask.Result.Contains(HttpConstants.SUCCESS)) { return(HttpConstants.SUCCESS); } else if (response.ToString().Contains(HttpConstants.UNAUTHORIZED)) { return(response.ToString()); } return(jsonTask.Result); } else { return(TextResources.MessageSomethingWentWrong); } } catch (Exception) { return(TextResources.MessageSomethingWentWrong); } }
private async Task AddAuditEntry(UserNotificationSetting setting) { await _mediator.SendAsync(new CreateAuditCommand { EasAuditMessage = new EasAuditMessage { Category = "UPDATED", Description = $"User {setting.UserId} has updated email notification setting for account {setting.HashedAccountId}", ChangedProperties = new List <PropertyUpdate> { new PropertyUpdate { PropertyName = "ReceiveNotifications", NewValue = setting.ReceiveNotifications.ToString() } }, RelatedEntities = new List <Entity> { new Entity { Id = setting.UserId.ToString(), Type = "User" } }, AffectedEntity = new Entity { Type = "UserAccountSetting", Id = setting.Id.ToString() } } }); }
public JsonResult UpdateNotificationSettings(UserNotificationSetting model) { model.UserID = LOGGEDIN_USER.UserID; var result = _userManager.SetUserNotificationSettings(model); return(Json(result)); }
public void Should_Delete() { UserNotificationSetting userNotificationSetting = new UserNotificationSetting(operationCode, cr, notificationCodeId, sms, email, userRoleId); userNotificationSetting.Delete(); Assert.Equal(ObjectState.Deleted, userNotificationSetting.State); }
/// <summary> /// The update subscribe ui. /// </summary> /// <param name="selectedValue"> /// The selected value. /// </param> private void UpdateSubscribeUI(UserNotificationSetting selectedValue) { bool showSubscribe = !(selectedValue == UserNotificationSetting.AllTopics || selectedValue == UserNotificationSetting.NoNotification); this.SubscribeHolder.Visible = showSubscribe; }
public void Should_UpdateNotificationSetting() { UserNotificationSetting userNotificationSetting = new UserNotificationSetting(operationCode, cr, notificationCodeId, sms, email, userRoleId); userNotificationSetting.UpdateNotificationSetting(emailEnabled, _SMSEnabled, isAllowedtoEditMail, isAllowedtoEditSMS); Assert.True(userNotificationSetting.Email); Assert.True(userNotificationSetting.Sms); }
public UserNotificationSetting GetUserNotificationSetting() { UserNotificationSetting userNotificationSetting = new UserNotificationSetting("123", 1, 1, false, false, 1); UserProfile user = new UserProfile(1123, "User Name", "Full Name", "0505050500", "*****@*****.**", new List <UserNotificationSetting>(1)); PropertyInfo userProp = userNotificationSetting.GetType().GetProperty("User"); userProp.SetValue(userNotificationSetting, user); return(userNotificationSetting); }
public List <UserNotificationSetting> GetUserNotificationSettings() { var setting = new UserNotificationSetting("123", "456", 1, false, false, 1); List <UserNotificationSetting> userNotificationSetting = new List <UserNotificationSetting>(); setting.SetIdForTest(100); setting.setNotificationOperationCodeForTest(); userNotificationSetting.Add(setting); return(userNotificationSetting); }
public UserProfile GetUserProfileData() { UserNotificationSetting setting = new UserNotificationSetting("code", 1, 1, true, true, 1); List <UserNotificationSetting> settings = new List <UserNotificationSetting>() { setting }; UserProfile userProfile = new UserProfile(1, "user name", "full name", "mobile", "email", settings); return(userProfile); }
public void Should_Construct_UserNotificationSetting_Second() { UserNotificationSetting userNotificationSetting = new UserNotificationSetting(operationCode, userProfileId, notificationCodeId, sms, email, userRoleId); _ = new UserNotificationSetting(); _ = userNotificationSetting.User; _ = userNotificationSetting.Supplier; _ = userNotificationSetting.NotificationOperationCode; _ = userNotificationSetting.UserRole; userNotificationSetting.ShouldNotBeNull(); }
public Supplier GetSupplierData() { List <UserNotificationSetting> userNotificationSettings = new List <UserNotificationSetting>(); UserNotificationSetting userNotificationSetting = new UserNotificationSetting("opcode", _Cr, 1, true, true, 1); userNotificationSetting.SetIdForTest(100); userNotificationSetting.setNotificationOperationCodeForTest(); userNotificationSettings.Add(userNotificationSetting); Supplier supplier = new Supplier(_Cr, _Cr, userNotificationSettings); supplier.UpdateNotificationSetting(100, true, true); return(supplier); }
public List <UserNotificationSetting> GetUserNotificationSettingWithProfileId() { var generalSetting = new UserNotificationSetting("123", 1, 1, true, true, 1); List <UserNotificationSetting> userNotificationSetting = new List <UserNotificationSetting>(); userNotificationSetting.Add(generalSetting); UserProfile user = new UserProfile(102, "User Name", "Full Name", "0505050500", "*****@*****.**", new List <UserNotificationSetting>(1)); PropertyInfo userProp = generalSetting.GetType().GetProperty("User"); userProp.SetValue(generalSetting, user); return(userNotificationSetting); }
public void Should_AddMissingNotificationSettings() { UserNotificationSetting userNotificationSetting = new UserNotificationSetting(operationCode, cr, notificationCodeId, sms, isEmail, userRoleId); UserProfile userProfile = new UserProfile(userId, userName, fullName, mobile, email, new List <UserNotificationSetting>() { new UserNotificationSetting() }); userProfile.AddMissingNotificationSettings(new List <UserNotificationSetting>() { userNotificationSetting }); Assert.NotEmpty(userProfile.NotificationSetting); }
/// <summary> /// Loads the data. /// </summary> /// <param name="displayCount">if set to <c>true</c> [display count].</param> public void LoadData(bool displayCount) { int notificationCount = 0; if (displayCount) { //Check whether this user is an active project member. ProjectUser puser = DataContext.ProjectUsers.Where(pu => pu.UserId == UserID && pu.ProjectId == ProjectID && pu.IsActive == true).FirstOrDefault(); //Only display notification count if the user is an active project member if (puser != null) { UserNotificationSetting unf = DataContext.UserNotificationSettings.Where(us => us.UserID == UserID && us.RelatedTable == "Project" && us.RelatedId == ProjectID).FirstOrDefault(); int lastNotificationId = unf == null ? 0 : unf.LastNotificationId.Value; bool showMyNotifications = unf == null ? false : unf.ShowMyNotifications; notificationCount = (from nf in DataContext.Notifications where nf.ProjectId == ProjectID && (nf.NotificationId > lastNotificationId) && (showMyNotifications || nf.CreatedByUserId != UserID) select nf).Count(); } } lnkProjectNotifications.HRef = string.Format("~/Project/ProjectNotifications.aspx?projectid={0}", ProjectID); if (CssClass != string.Empty) { lnkProjectNotifications.Attributes["class"] = CssClass; } if (notificationCount > 0) { lnkNotificationCount.Visible = true; lnkNotificationCount.InnerText = notificationCount.ToString(); lnkNotificationCount.HRef = lnkProjectNotifications.HRef; } else { lnkNotificationCount.Visible = false; } }
public static List <NotificationDTD> GetNotificationData(string lastNotificationId, string ShowMyNotifications, string GetLatestNotificationsOnly, string IsScroll, string showMyNotificationsClicked, string projectId) { using (PageBase pb = new PageBase()) { const int maximumRecordsToShow = 20; int lastNotificationIdValue = Convert.ToInt32(lastNotificationId); int projectIdValue = Convert.ToInt32(projectId); var notifications = (from p in pb.DataContext.Projects join n in pb.DataContext.Notifications on p.ProjectId equals n.ProjectId join u in pb.DataContext.Users on n.CreatedByUserId equals u.UserId join cModules in pb.DataContext.Codes on n.ModuleTypeCodeId equals cModules.CodeId join cOperations in pb.DataContext.Codes on n.OperationTypeCodeId equals cOperations.CodeId orderby n.NotificationId descending where p.ProjectId == projectIdValue select new { NotificationId = n.NotificationId, p.ProjectId, ProjectName = p.ProjectName, OperationType = cOperations.Value, RelatedId = n.RelatedId, Module = cModules.Value, Message = n.Message, EventDate = n.CreatedDate, CreatedbyUserID = u.UserId }); #region Filters UserNotificationSetting userNotificationSetting = (from un in pb.DataContext.UserNotificationSettings where un.RelatedTable == "Project" && un.RelatedId == projectIdValue && un.UserID == pb.UserID select un).FirstOrDefault(); //To apply styles for new notifications int usersLastViewdNotificationId = 0; if (userNotificationSetting != null) { usersLastViewdNotificationId = (int)userNotificationSetting.LastNotificationId; } int maxNotificationID = 0; if (notifications.Count() > 0) { maxNotificationID = (from n in notifications select n.NotificationId).Max(); } if (!Convert.ToBoolean(ShowMyNotifications)) { notifications = (notifications.Where(n => n.CreatedbyUserID != pb.UserID)); } bool onlyLatestNotifications = Convert.ToBoolean(GetLatestNotificationsOnly); if (onlyLatestNotifications) { if (userNotificationSetting != null) { lastNotificationIdValue = (int)userNotificationSetting.LastNotificationId; } notifications = (notifications.Where(n => n.NotificationId > lastNotificationIdValue)); } else { if (lastNotificationIdValue > 0) { notifications = (notifications.Where(n => n.NotificationId < lastNotificationIdValue).Take(maximumRecordsToShow)); } else { notifications = (notifications.Take(maximumRecordsToShow)); } } #endregion Filters #region Update UserNotification setting if (userNotificationSetting == null) { //Add an UserNotificationsetting record userNotificationSetting = new UserNotificationSetting(); userNotificationSetting.RelatedTable = "Project"; userNotificationSetting.UserID = pb.UserID; userNotificationSetting.RelatedId = projectIdValue; userNotificationSetting.LastNotificationId = maxNotificationID; userNotificationSetting.ShowMyNotifications = Convert.ToBoolean(ShowMyNotifications); userNotificationSetting.CreatedBy = pb.UserID; userNotificationSetting.CreatedDate = Now; userNotificationSetting.LastUpdatedBy = pb.UserID; userNotificationSetting.LastUpdatedDate = Now; pb.DataContext.UserNotificationSettings.AddObject(userNotificationSetting); } else if (!Convert.ToBoolean(IsScroll)) { if (onlyLatestNotifications) { userNotificationSetting.LastNotificationId = maxNotificationID; } else if (userNotificationSetting.LastNotificationId < maxNotificationID) { userNotificationSetting.LastNotificationId = maxNotificationID; } if (Convert.ToBoolean(showMyNotificationsClicked)) { userNotificationSetting.ShowMyNotifications = Convert.ToBoolean(ShowMyNotifications); } userNotificationSetting.LastUpdatedBy = pb.UserID; userNotificationSetting.LastUpdatedDate = Now; } pb.DataContext.SaveChanges(); #endregion Update UserNotification setting //Initialize the list to be exported List <NotificationDTD> notificationsList = new List <NotificationDTD>(); if (notifications.Count() > 0) { foreach (var n in notifications) { NotificationDTD nDTD = new NotificationDTD(); nDTD.NotificationId = n.NotificationId; switch (n.OperationType) { case "ADD": nDTD.ImageURL = "../Common/Images/add.png"; break; case "EDIT": nDTD.ImageURL = "../Common/Images/edit.png"; break; case "DELETE": nDTD.ImageURL = "../Common/Images/delete.png"; break; default: break; } switch (n.Module) { case "PROJECT": nDTD.ModuleName = string.Format("Project Details"); if (n.RelatedId != 0) //This is to redirect users to the project attachment tab. If there are notifications for other tabs, Add coulmn to notification table to cater sub module type { nDTD.ModuleHref = string.Format("../Project/ProjectDetails.aspx?projectid={0}&TabId=1", n.ProjectId); } else { nDTD.ModuleHref = string.Format("../Project/ProjectDetails.aspx?projectid={0}", n.ProjectId); } break; case "SCHEDULE": nDTD.ModuleName = "Project Schedule"; nDTD.ModuleHref = string.Format("../Project/ProjectSchedule.aspx?projectid={0}", n.ProjectId); break; case "PROJTEAM": nDTD.ModuleName = "Project Team"; nDTD.ModuleHref = string.Format("../Project/ProjectTeam.aspx?projectid={0}", n.ProjectId); break; case "ITEMBRIEF": case "TASK": case "ITEMBRIEFBOOKING": case "ITEMBRIEFMEDIA": int itemBriefId = 0; itemBriefId = (int)n.RelatedId; if (n.OperationType != "DELETE" || n.Module == "TASK") //When the item brief is deleted, there is no itembrief record to get the name { var itemBrief = (from i in pb.DataContext.ItemBriefs where i.ItemBriefId == itemBriefId select new { Name = i.Name }).FirstOrDefault(); if (itemBrief != null) { nDTD.ModuleName = itemBrief.Name; if (n.Module == "ITEMBRIEF") { nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefDetails.aspx?ItemBriefId={0}", itemBriefId); } else if (n.Module == "TASK") { nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefDetails.aspx?ItemBriefId={0}&selectedTab={1}", n.RelatedId, "Tasks"); } else if (n.Module == "ITEMBRIEFMEDIA") { nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefDetails.aspx?ItemBriefId={0}&TabId=2", itemBriefId); } else if (n.Module == "ITEMBRIEFBOOKING") { nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefDetails.aspx?ItemBriefId={0}&TabId=3", itemBriefId); } } else { nDTD.ModuleName = "Item Brief"; nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefList.aspx?projectid={0}", n.ProjectId); } } else { nDTD.ModuleName = "Item Brief"; nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefList.aspx?projectid={0}", n.ProjectId); } break; case "ITEMLIST": nDTD.ModuleName = "Item Brief List"; nDTD.ModuleHref = string.Format("../ItemBrief/ItemBriefList.aspx?projectid={0}", n.ProjectId); break; default: break; } nDTD.Message = n.Message; nDTD.EventDate = Utils.FormatDatetime(Convert.ToDateTime(n.EventDate), true); if (n.NotificationId > usersLastViewdNotificationId) { nDTD.Style = "NotificationBlockWithBackground"; } else { nDTD.Style = "NotificationBlock"; } notificationsList.Add(nDTD); } } return(notificationsList); } }
/// <summary> /// Updates the information in the YAF DB from the ASP.NET Membership user information. /// Called once per session for a user to sync up the data /// </summary> /// <param name="user">Current Membership User</param> /// <param name="pageBoardID">Current BoardID</param> /// <param name="roles">The DNN user roles.</param> /// <returns> /// The update forum user. /// </returns> public static int?UpdateForumUser([NotNull] MembershipUser user, int pageBoardID, string[] roles = null) { if (user == null) { // Check to make sure its not a guest return(null); } int userId = UserMembershipHelper.GetUserIDFromProviderUserKey(user.ProviderUserKey); if (userId == UserMembershipHelper.GuestUserId) { return(userId); } if (user.ProviderUserKey == null) { // problem -- log and move on... YafContext.Current.Get <ILogger>() .Log( userId, "UpdateForumUser", "Null User Provider Key for UserName {0}. Please check your provider key settings for your ASP.NET membership provider." .FormatWith(user.UserName)); return(userId); } // is this a new user? bool isNewUser = userId <= 0; userId = LegacyDb.user_aspnet( pageBoardID, user.UserName, null, user.Email, user.ProviderUserKey, user.IsApproved); // get user groups... DataTable groupTable = LegacyDb.group_member(pageBoardID, userId); string[] userRoles = GetRolesForUser(user.UserName); if (Config.IsDotNetNuke && roles != null) { userRoles = roles; } if (Config.IsMojoPortal) { string roles1 = userRoles.Where(t => !string.IsNullOrEmpty(t)) .Aggregate(string.Empty, (current, t) => current.Trim() + "," + t.Trim()); userRoles = roles1.Trim(',').Split(','); } // add groups... foreach (string role in userRoles.Where(role => !GroupInGroupTable(role, groupTable))) { // add the role... LegacyDb.user_setrole(pageBoardID, user.ProviderUserKey, role); } // remove groups... foreach (DataRow row in groupTable.AsEnumerable().Where(row => !userRoles.Contains(row["Name"].ToString()))) { // remove since there is no longer an association in the membership... LegacyDb.usergroup_save(userId, row["GroupID"], 0); } if (!isNewUser || userId <= 0) { return(userId); } try { UserNotificationSetting defaultNotificationSetting = YafContext.Current.Get <YafBoardSettings>().DefaultNotificationSetting; bool defaultSendDigestEmail = YafContext.Current.Get <YafBoardSettings>().DefaultSendDigestEmail; // setup default notifications... bool autoWatchTopicsEnabled = defaultNotificationSetting == UserNotificationSetting.TopicsIPostToOrSubscribeTo; // save the settings... LegacyDb.user_savenotification( userId, true, autoWatchTopicsEnabled, defaultNotificationSetting, defaultSendDigestEmail); } catch (Exception ex) { YafContext.Current.Get <ILogger>() .Log( userId, "UpdateForumUser", "Failed to save default notifications for new user: {0}".FormatWith(ex)); } return(userId); }
/// <summary> /// Accepts the invitation. /// </summary> /// <param name="invitationId">The invitation identifier.</param> /// <param name="userId">The user identifier.</param> public void AcceptInvitation(int invitationId, int userId) { Invitation invitation = DataContext.Invitations.Where(inv => inv.InvitationId == invitationId).FirstOrDefault(); var invitationUserRoles = DataContext.InvitationUserRoles.Where(iur => iur.InvitationId == invitationId && iur.IsActive); Code invitationTypeCode = Utils.GetCodeByCodeId(invitation.InvitationTypeCodeId); User user = GetUser(userId); #region Create project/company user if (invitationTypeCode.Value == "PROJECTTEAM") { int projectId = invitation.RelatedId; InvitationUserRole projectInvitationUserRole = invitationUserRoles.FirstOrDefault(); if (projectInvitationUserRole != null) { //Create a new project user and save ProjectUser projUser = new ProjectUser(); projUser.ProjectId = projectId; projUser.UserId = invitation.ToUserId.Value; projUser.ProjectUserTypeCodeId = projectInvitationUserRole.UserTypeCodeId; projUser.Role = invitation.ProjectRole; projUser.IsActive = true; projUser.CreatedByUserId = projUser.LastUpdatedByUserId = userId; projUser.CreatedDate = projUser.LastUpdatedDate = Utils.Now; projUser.CanSeeBudgetSummary = invitation.CanSeeProjectBudgetSummary; DataContext.ProjectUsers.AddObject(projUser); #region Notifications Data.Notification nf = new Data.Notification(); nf.ModuleTypeCodeId = Utils.GetCodeIdByCodeValue("ModuleType", "PROJTEAM"); nf.OperationTypeCodeId = Utils.GetCodeIdByCodeValue("OperationType", "ADD"); nf.RelatedId = invitation.RelatedId; nf.ProjectId = invitation.RelatedId; nf.Message = string.Format("{0} accepted the Project invitation.", (user.FirstName + " " + user.LastName).Trim()); nf.CreatedByUserId = nf.LastUpdatedByUserId = userId; nf.CreatedDate = nf.LastUpdatedDate = Utils.Now; DataContext.Notifications.AddObject(nf); #endregion Notifications #region Project Notification Setting //Get the current latest notification Id for the project. int maxNotificationId = DataContext.Notifications.Where(pnf => pnf.ProjectId == projectId).Max(pnf => pnf.NotificationId); //Create a project notification setting for this user (if it doesn't exist already) UserNotificationSetting unf = DataContext.UserNotificationSettings.Where(s => s.RelatedTable == "Project" && s.RelatedId == projectId && s.UserID == userId).FirstOrDefault(); if (unf == null) { unf = new UserNotificationSetting(); unf.RelatedTable = "Project"; unf.RelatedId = projectId; unf.UserID = userId; unf.LastNotificationId = maxNotificationId; unf.CreatedBy = unf.LastUpdatedBy = userId; unf.CreatedDate = unf.LastUpdatedDate = Utils.Now; DataContext.UserNotificationSettings.AddObject(unf); } #endregion Project Notification Setting //Update Project Daily Usage Summary //ProjectUsageHandler.UpdateProjectUsage(DataContext.Projects.Where(p => p.ProjectId == projectId).FirstOrDefault(), userId, projUser.UserId, false, Utils.Today, DataContext); } } else if (invitationTypeCode.Value == "COMPANYADMIN" || invitationTypeCode.Value == "INVENTORYTEAM") { CompanyBL companyBL = new CompanyBL(DataContext); CompanyUser companyUser = companyBL.GetCompanyUserByUserIdAndCompanyId(userId, invitation.RelatedId); bool addNewCompanyUser = false; if (companyUser == null) { companyUser = new CompanyUser(); companyUser.CompanyId = invitation.RelatedId; companyUser.UserId = invitation.ToUserId.Value; companyUser.CreatedDate = companyUser.LastUpdatedDate = Utils.Now; addNewCompanyUser = true; } //companyUser.CompanyUserTypeCodeId = invitation.UserTypeCodeId; companyUser.IsActive = true; companyUser.CreatedByUserId = companyUser.LastUpdatedByUserId = userId; foreach (InvitationUserRole invitationUserRole in invitationUserRoles) { companyUser.CompanyUserRoles.Add( new CompanyUserRole { IsActive = true, CompanyUserTypeCodeId = invitationUserRole.UserTypeCodeId, CreatedByUserId = userId, CreatedDate = Utils.Now, LastUpdatedByUserId = userId, LastUpdatedDate = Utils.Now, LocationId = invitationUserRole.LocationId } ); } if (addNewCompanyUser) { DataContext.CompanyUsers.AddObject(companyUser); } } #endregion Create project/company user //Mark the invitation as Accepted invitation.InvitationStatusCodeId = Utils.GetCodeIdByCodeValue("InvitationStatus", "ACCEPTED"); invitation.LastUpdatedByUserId = userId; invitation.LastUpdatedDate = Utils.Now; DataContext.SaveChanges(); #region Check for pending invitations to the same project/company and discard them int pendingInvitationCodeId = Utils.GetCodeIdByCodeValue("InvitationStatus", "PENDING"); var simillarInvitations = DataContext.Invitations.Where(inv => inv.ToUserId == userId && inv.InvitationStatusCodeId == pendingInvitationCodeId && inv.RelatedId == invitation.RelatedId && inv.InvitationTypeCodeId == invitation.InvitationTypeCodeId); foreach (Invitation inv in simillarInvitations) { DataContext.DeleteInvitation(inv.InvitationId); } #endregion Check for pending invitations to the same project/company and discard them }
/// <summary> /// The user_savenotification. /// </summary> /// <param name="mid"> /// The mid. /// </param> /// <param name="userId"> /// The user id. /// </param> /// <param name="pmNotification"> /// The pm notification. /// </param> /// <param name="autoWatchTopics"> /// The auto watch topics. /// </param> /// <param name="notificationType"> /// The notification type. /// </param> /// <param name="dailyDigest"> /// The daily digest. /// </param> public static void user_savenotification( int? mid, object userId, object pmNotification, object autoWatchTopics, UserNotificationSetting notificationType, object dailyDigest) { using (var sc = new VzfSqlCommand(mid)) { sc.Parameters.Add(sc.CreateParameter(DbType.Int32, "i_UserID", userId)); sc.Parameters.Add(sc.CreateParameter(DbType.Boolean, "i_PMNotification", pmNotification)); sc.Parameters.Add(sc.CreateParameter(DbType.Boolean, "i_AutoWatchTopics", autoWatchTopics)); sc.Parameters.Add(sc.CreateParameter(DbType.Int32, "i_NotificationType", notificationType.ToInt())); sc.Parameters.Add(sc.CreateParameter(DbType.Boolean, "i_DailyDigest", dailyDigest)); sc.CommandText.AppendObjectQuery("user_savenotification", mid); sc.ExecuteNonQuery(CommandType.StoredProcedure); } }
public async Task <IActionResult> Register(RegisterModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.UserName); if (user != null) { ModelState.AddModelError("reg-err", "Username already exists"); return(View("Index")); } user = new QueueItUser { Id = Guid.NewGuid().ToString(), FirstName = model.FirstName, LastName = model.LastName, UserName = model.UserName, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var team = new Team { Name = "Personal", CreatorId = user.Id, Description = "This is your Personal Team. " + "Use it to keep track of your Queues and Tasks " + "that you might not want to share with your other teams.", IsPrivate = true, CreatedOn = DateTime.Now }; _db.Teams.Add(team); _db.SaveChanges(); var userTeam = new UserTeam { UserId = user.Id, TeamId = team.Id, IsAdmin = true }; _db.UserTeams.Add(userTeam); _db.SaveChanges(); var queue = new Models.Queue { Title = "Personal Queue", TeamId = team.Id, CreatorId = user.Id, IsPrivate = true, CreatedOn = DateTime.Now, UpdatedOn = DateTime.Now }; var userNotificationSetting = new UserNotificationSetting { UserId = user.Id, NotificationsOn = true }; _db.UserNotificationSettings.Add(userNotificationSetting); _db.SaveChanges(); _db.Queues.Add(queue); _db.SaveChanges(); var token = await _userManager.GenerateEmailConfirmationTokenAsync(user); var confirmationEmail = Url.Action("ConfirmEmailAddress", "Home", new { token = token, email = user.Email }, Request.Scheme); System.IO.File.WriteAllText("confirmation.txt", confirmationEmail); var fullName = user.FirstName + " " + user.LastName; const string from = "*****@*****.**"; const string fromName = "QueueIT"; const string subject = "QueueIT: Confirm Your Email"; var body = "<br/>Your username is:<br/><br/><b>" + user.UserName + "</b><br/><br/>Visit this link to confirm your email and gain access to the site. <br/><br/>" + confirmationEmail + "<br/><br/>Thanks for using the site!<br/><br/>"; _emailSender.SendEmail(user.Email, fullName, @from, fromName, subject, body, true); } else { foreach (var error in result.Errors) { ModelState.AddModelError("reg-err", error.Description); } return(View("Index")); } return(View("Index")); } ModelState.AddModelError("reg-err", ""); return(View("Index")); }