public static void CopyNotificationSettings(NotificationsSetting origin, EditNotificationsViewModel setting)
        {
            origin.GeneralByEmail     = setting.GeneralByEmail;
            origin.GeneralByMobileApp = setting.GeneralByMobileApp;
            origin.GeneralBySMS       = setting.GeneralBySMS;
            origin.GeneralByPhone     = setting.GeneralByPhone;

            origin.DiscountAnTipsByEmail   = setting.DiscountAnTipsByEmail;
            origin.DiscountAnTipsMobileApp = setting.DiscountAnTipsMobileApp;
            origin.DiscountAnTipsBySMS     = setting.DiscountAnTipsBySMS;
            origin.DiscountAnTipsByPhone   = setting.DiscountAnTipsByPhone;

            origin.RemindByEmail     = setting.RemindByEmail;
            origin.RemindByMobileApp = setting.RemindByMobileApp;
            origin.RemindBySMS       = setting.RemindBySMS;
            origin.RemindByPhone     = setting.RemindByPhone;

            origin.RulesAndCommunityByEmail     = setting.RulesAndCommunityByEmail;
            origin.RulesAndCommunityByMobileApp = setting.RulesAndCommunityByMobileApp;
            origin.RulesAndCommunityBySMS       = setting.RulesAndCommunityBySMS;
            origin.RulesAndCommunityByPhone     = setting.RulesAndCommunityByPhone;

            origin.ServiceByEmail     = setting.ServiceByEmail;
            origin.ServiceByMobileApp = setting.ServiceByMobileApp;
            origin.ServiceBySMS       = setting.ServiceBySMS;
            origin.ServiceByPhone     = setting.ServiceByPhone;
        }
Beispiel #2
0
        public async Task <IActionResult> EditNotifications(EditNotificationsViewModel viewModel)
        {
            User currentUser = await userManager.GetUserAsync(HttpContext.User);

            NotificationsSetting notificationsSettings = context.NotificationSettings.Where(s => s.User == currentUser).Single();

            UserAccountServiceLogic.CopyNotificationSettings(notificationsSettings, viewModel);

            await context.SaveChangesAsync();

            return(RedirectToAction("Edit"));
        }
Beispiel #3
0
        public async Task <IActionResult> Index(EditNotificationsViewModel model)
        {
            var user = await _userManager.FindByIdAsync(model.Id.ToString());

            if (user == null)
            {
                return(NotFound());
            }

            var editProfileViewModel = new EditNotificationsViewModel()
            {
                Id = user.Id
            };

            // Build view
            await _editProfileViewProvider.ProvideUpdateAsync(editProfileViewModel, this);

            // Ensure model state is still valid after view providers have executed
            if (ModelState.IsValid)
            {
                _alerter.Success(T["Notifications Updated Successfully!"]);
                return(RedirectToAction(nameof(Index)));
            }

            // if we reach this point some view model validation
            // failed within a view provider, display model state errors
            foreach (var modelState in ViewData.ModelState.Values)
            {
                foreach (var error in modelState.Errors)
                {
                    _alerter.Danger(T[error.ErrorMessage]);
                }
            }

            return(await Index());
        }
Beispiel #4
0
        public async Task <IActionResult> Index()
        {
            // We need to be authenticated to access notification settings
            var user = await _contextFacade.GetAuthenticatedUserAsync();

            if (user == null)
            {
                return(NotFound());
            }

            // Breadcrumb
            _breadCrumbManager.Configure(builder =>
            {
                builder.Add(S["Home"], home => home
                            .Action("Index", "Home", "Plato.Core")
                            .LocalNav()
                            ).Add(S["Your Account"]);
            });

            // Get saved notification types
            var userNotificationSettings = user.GetOrCreate <UserNotificationTypes>();

            // Get all notification types to enable by default
            var defaultNotificationTypes     = _notificationTypeManager.GetDefaultNotificationTypes(user.RoleNames);
            var defaultUserNotificationTypes = new List <UserNotificationType>();

            foreach (var notificationType in defaultNotificationTypes)
            {
                defaultUserNotificationTypes.Add(new UserNotificationType(notificationType.Name));
            }

            // Holds our list of enabled notification types
            var enabledNotificationTypes = new List <UserNotificationType>();

            // We have previously saved settings
            if (userNotificationSettings.NotificationTypes != null)
            {
                // Add all user specified notification types
                enabledNotificationTypes.AddRange(userNotificationSettings.NotificationTypes);

                // Loop through all default notification types to see if the user has saved
                // a value (on or off) for that notification type, if no value have been previously saved
                // ensure the default notification type is added to our list of enabled notification types
                foreach (var userNotification in defaultUserNotificationTypes)
                {
                    var foundNotification = enabledNotificationTypes.FirstOrDefault(n =>
                                                                                    n.Name.Equals(userNotification.Name, StringComparison.OrdinalIgnoreCase));
                    if (foundNotification == null)
                    {
                        enabledNotificationTypes.Add(userNotification);
                    }
                }
            }
            else
            {
                // If we don't have any notification types ensure we enable all by default
                enabledNotificationTypes.AddRange(defaultUserNotificationTypes);
            }

            var editProfileViewModel = new EditNotificationsViewModel()
            {
                Id = user.Id
            };

            // Return view
            return(View((LayoutViewModel)await _editProfileViewProvider.ProvideEditAsync(editProfileViewModel, this)));
        }