public SettingsVm()
 {
     this.Profile = new EditProfileVm();
     PasswordChange = new ChangePasswordVM();
     IssueSettings = new DefaultIssueSettings();
     NotificationSettings = new UserEmailNotificationSettingsVM();
 }
Exemplo n.º 2
0
 public SettingsVm()
 {
     this.Profile         = new EditProfileVm();
     PasswordChange       = new ChangePasswordVM();
     IssueSettings        = new DefaultIssueSettings();
     NotificationSettings = new UserEmailNotificationSettingsVM();
 }
        public async Task SaveNotificationSettings(UserEmailNotificationSettingsVM model)
        {
            model.UserId = userSessionHelper.UserId;
            model.TeamId = userSessionHelper.TeamId;
            await userRepository.SaveNotificationSettings(model);

        }
 public ActionResult NotificationSettings(UserEmailNotificationSettingsVM model)
 {
     try
     {
         foreach (var setting in model.EmailSubscriptions)
         {
             var userNotification = new UserNotificationSubscription { TeamID = TeamID, UserID = UserID };
             userNotification.Subscribed = setting.IsSelected;
             userNotification.ModifiedDate = DateTime.UtcNow;
             userNotification.NotificationTypeID = setting.NotificationTypeID;
             repo.SaveUserNotificationSubscription(userNotification);
         }
         var msg = new AlertMessageStore();
         msg.AddMessage("success", "Notification Settings updated successfully");
         TempData["AlertMessages"] = msg;
         return RedirectToAction("NotificationSettings");
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return View("Error");
     }
 }
        public ActionResult NotificationSettings()
        {
            var vm = new UserEmailNotificationSettingsVM { TeamID = TeamID };
            var userSubscriptions = repo.GetUser(UserID).UserNotificationSubscriptions.ToList();

            var notificationTypes = repo.GetNotificationTypes().ToList();
            foreach (var item in notificationTypes)
            {
                var emailSubscription = new EmailSubscriptionVM { NotificationTypeID = item.ID, Name = item.Name };
                emailSubscription.IsSelected = userSubscriptions.Any(s => s.UserID == UserID && s.TeamID == TeamID && s.NotificationTypeID == item.ID && s.Subscribed == true);
                vm.EmailSubscriptions.Add(emailSubscription);
            }

            return View(vm);
        }
Exemplo n.º 6
0
        public async Task SaveNotificationSettings(UserEmailNotificationSettingsVM model)
        {
            //DELETE EXISTING 
            var q = @"DELETE FROM UserNotificationSubscription WHERE UserId=@userId and TeamId=@teamId;";
            using (var con = new SqlConnection(ConnectionString))
            {
                con.Open();
                await con.ExecuteAsync(q, new { @userId = model.UserId, @teamId = model.TeamId });

            }
            //Insert new
            foreach (var setting in model.EmailSubscriptions.Where(s => s.IsSelected))
            {
                var q2 = @"INSERT INTO
                    UserNotificationSubscription(UserID,NotificationTypeID,TeamId,Subscribed,ModifiedDate) VALUES
                    (@userId,@notificationTypeId,@teamId,@subscibed,@dt)";
                using (var con = new SqlConnection(ConnectionString))
                {
                    con.Open();
                    await con.ExecuteAsync(q2, new
                    {
                        @userId = model.UserId,
                        @subscibed = true,
                        @notificationTypeId = setting.NotificationTypeId,
                        @dt = DateTime.Now,
                        @teamId = model.TeamId
                    });

                }
            }

        }
        public UserEmailNotificationSettingsVM GetUserNotificationSettings(int userId,int teamId)
        {
            var userSubscriptions = new UserEmailNotificationSettingsVM();
            userSubscriptions.EmailSubscriptions = db.NotificationTypes.Select(s => new EmailSubscriptionVM {NotificationTypeID = s.ID, Name = s.Name}).ToList();

            var user = db.Users.FirstOrDefault(s => s.ID == userId);
            if (user != null && user.UserNotificationSubscriptions.Any())
            {
                var userSubScriptions = user.UserNotificationSubscriptions.ToList();
                foreach (var emailSubscriptionVm in userSubscriptions.EmailSubscriptions)
                {
                    emailSubscriptionVm.IsSelected =
                        userSubScriptions.Any(
                            s =>
                                s.NotificationTypeID == emailSubscriptionVm.NotificationTypeID && s.TeamID == teamId &&
                                s.Subscribed);
                }
                
            }
            return userSubscriptions;
        }
 public async Task<ActionResult> Notifications(UserEmailNotificationSettingsVM model)
 {
     await _userAccountManager.SaveNotificationSettings(model);
     SetMessage(MessageType.Success, "Settings updated successfully");
     return RedirectToAction("Index", "Settings");
 }