Exemple #1
0
        public static NotificationManageViewModel ToNotificationManageViewModel(IEnumerable <NotificationType> notificationTypes, int?type, int?to, string language)
        {
            var model = new NotificationManageViewModel();
            NotificationTypeViewModel   typeViewModel = new NotificationTypeViewModel();
            List <NotificationTypeList> typeList      = new List <NotificationTypeList>();

            model.Addresses = new List <AddressViewModel>();
            foreach (var notificationType in notificationTypes)
            {
                if ((int)notificationType.NotificationCategory == type)
                {
                    typeViewModel = new NotificationTypeViewModel
                    {
                        Id    = notificationType.Id,
                        Label = notificationType.Label,
                        NotificationTypeSettingId = notificationType.NotificationTypeSettingId,
                        Category = notificationType.NotificationCategory
                    };
                    model.Addresses = ToAddressViewModels(notificationType, to);
                }
                typeList.Add(new NotificationTypeList
                {
                    Id          = (int)notificationType.NotificationCategory,
                    Label       = notificationType.Label,
                    Description = GetNotificationTypeLabelDescription(notificationType.Label, language)
                });
            }
            model.NotificationTypeViewModel = typeViewModel;
            model.NotificationTypeList      = typeList;
            return(model);
        }
Exemple #2
0
        public async Task <ActionResult> SMTP()
        {
            var appSettings = await _prepareService.GetAllAppSettings();

            var model = new NotificationManageViewModel
            {
                CanSendMail = true
            };

            try
            {
                model.UseAnonymMode = appSettings.Any(_ => _.Key == "SMTP_UseAnonymMode") ? bool.Parse(Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_UseAnonymMode").Value)) : false;
                model.SenderEmail   = appSettings.Any(_ => _.Key == "Email_Sender_Address") ? Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "Email_Sender_Address").Value) : string.Empty;
                model.Password      = appSettings.Any(_ => _.Key == "Email_Sender_Password") ? Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "Email_Sender_Password").Value) : string.Empty;
                model.ServerAddress = appSettings.Any(_ => _.Key == "SMTP_Client") ? Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_Client").Value) : string.Empty;
                model.ServerPort    = appSettings.Any(_ => _.Key == "SMTP_Port") ? int.Parse(Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_Port").Value)) : 25;
                model.UseSSL        = appSettings.Any(_ => _.Key == "SMTP_EnableSsl") ? bool.Parse(Encoding.UTF8.GetString(appSettings.Single(_ => _.Key == "SMTP_EnableSsl").Value)) : true;
                if (string.IsNullOrEmpty(model.SenderEmail))
                {
                    model.CanSendMail = false;
                }
                else if (!model.UseAnonymMode && string.IsNullOrEmpty(model.Password))
                {
                    model.CanSendMail = false;
                }
                else if (string.IsNullOrEmpty(model.ServerAddress))
                {
                    model.CanSendMail = false;
                }
            }
            catch
            {
                model.CanSendMail = false;
            }
            return(PartialView(model));
        }