コード例 #1
0
        //public async Task<ActionResult> DeleteAddress(int key)
        //{
        //    var to = Convert.ToInt16(Request.Headers.GetValues("To")[0]);
        //    var type = Convert.ToInt32(Request.Headers.GetValues("Type")[0]);
        //    var address = Request.Headers.GetValues("Address")[0];
        //    var notificationTypes = await _notificationService.GetNotificationTypes((NotificationCategory)type);
        //    var notificationType = notificationTypes.FirstOrDefault();
        //    notificationType.NotificationTypeSetting.MarkAsModified();
        //    switch (to)
        //    {
        //        case (int)ToType.Recipients:
        //            var recipientList = NotificationTypeMapper.toAddressViewModels(notificationType, to);
        //            var recipientToRemove = recipientList.First(r => r.Address == address);
        //            recipientList.Remove(recipientToRemove);
        //            notificationType.NotificationTypeSetting.Recipients = recipientList.Any() ? string.Join(",", recipientList.Select(l => l.Address)) : null;
        //            await _notificationService.SaveNotificationType(notificationType);
        //            break;
        //        case (int)ToType.RecipientCcs:
        //            var ccsList = NotificationTypeMapper.toAddressViewModels(notificationType, to);
        //            var ccToRemove = ccsList.First(r => r.Address == address);
        //            ccsList.Remove(ccToRemove);
        //            notificationType.NotificationTypeSetting.RecipientCcs = ccsList.Any() ? string.Join(",", ccsList.Select(l => l.Address)) : null;
        //            await _notificationService.SaveNotificationType(notificationType);
        //            break;
        //        case (int)ToType.RecipientBccs:
        //            var bccsList = NotificationTypeMapper.toAddressViewModels(notificationType, to);
        //            var bccToRemove = bccsList.First(r => r.Address == address);
        //            bccsList.Remove(bccToRemove);
        //            notificationType.NotificationTypeSetting.RecipientBccs = bccsList.Any() ? string.Join(",", bccsList.Select(l => l.Address)) : null;
        //            await _notificationService.SaveNotificationType(notificationType);
        //            break;
        //        default:
        //            break;
        //    }
        //    return Json(key, JsonRequestBehavior.AllowGet);
        //}

        public async Task <ActionResult> DeleteAddress(int key, int To, int Type)
        {
            try
            {
                int to                = To;
                int type              = Type;
                var addressId         = key;
                var notificationTypes = await _notificationService.GetNotificationTypes((NotificationCategory)type);

                var notificationType = notificationTypes.FirstOrDefault();
                notificationType.NotificationTypeSetting.MarkAsModified();
                switch (to)
                {
                case (int)ToType.Recipients:
                    var recipientList     = NotificationTypeMapper.ToAddressViewModels(notificationType, to);
                    var recipientToRemove = recipientList.First(r => r.Id == addressId);
                    recipientList.Remove(recipientToRemove);
                    notificationType.NotificationTypeSetting.Recipients = recipientList.Any() ? string.Join(",", recipientList.Select(l => l.Address)) : null;
                    await _notificationService.SaveNotificationType(notificationType);

                    break;

                case (int)ToType.RecipientCcs:
                    var ccsList    = NotificationTypeMapper.ToAddressViewModels(notificationType, to);
                    var ccToRemove = ccsList.First(r => r.Id == addressId);
                    ccsList.Remove(ccToRemove);
                    notificationType.NotificationTypeSetting.RecipientCcs = ccsList.Any() ? string.Join(",", ccsList.Select(l => l.Address)) : null;
                    await _notificationService.SaveNotificationType(notificationType);

                    break;

                case (int)ToType.RecipientBccs:
                    var bccsList    = NotificationTypeMapper.ToAddressViewModels(notificationType, to);
                    var bccToRemove = bccsList.First(r => r.Id == addressId);
                    bccsList.Remove(bccToRemove);
                    notificationType.NotificationTypeSetting.RecipientBccs = bccsList.Any() ? string.Join(",", bccsList.Select(l => l.Address)) : null;
                    await _notificationService.SaveNotificationType(notificationType);

                    break;

                default:
                    break;
                }
                var model = await GetNotificationManage(type, to);

                return(Json(model.Addresses, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, ex.Message));
            }
        }
コード例 #2
0
        public async Task <ActionResult> InsertAddress(CRUDModel <AddressViewModel> address)
        {
            var to   = Convert.ToInt16(address.Params["To"]);
            var type = Convert.ToInt32(address.Params["Type"]);
            var notificationTypes = await _notificationService.GetNotificationTypes((NotificationCategory)type);

            var notificationType = notificationTypes.FirstOrDefault();

            notificationType.NotificationTypeSetting.MarkAsModified();
            switch (to)
            {
            case (int)ToType.Recipients:
                var recipientList = NotificationTypeMapper.ToAddressViewModels(notificationType, to);
                recipientList.Add(new AddressViewModel {
                    Address = address.Value.Address
                });
                notificationType.NotificationTypeSetting.Recipients = string.Join(",", recipientList.Select(l => l.Address));
                var newRecipient = await _notificationService.SaveNotificationType(notificationType);

                address.Value.Id = recipientList.Last().Id + 1;
                break;

            case (int)ToType.RecipientCcs:
                var ccsList = NotificationTypeMapper.ToAddressViewModels(notificationType, to);
                ccsList.Add(new AddressViewModel {
                    Address = address.Value.Address
                });
                notificationType.NotificationTypeSetting.RecipientCcs = string.Join(",", ccsList.Select(l => l.Address));
                var newCc = await _notificationService.SaveNotificationType(notificationType);

                address.Value.Id = ccsList.Last().Id + 1;
                break;

            case (int)ToType.RecipientBccs:
                var bccsList = NotificationTypeMapper.ToAddressViewModels(notificationType, to);
                bccsList.Add(new AddressViewModel {
                    Address = address.Value.Address
                });
                notificationType.NotificationTypeSetting.RecipientBccs = string.Join(",", bccsList.Select(l => l.Address));
                var newBcc = await _notificationService.SaveNotificationType(notificationType);

                address.Value.Id = bccsList.Last().Id + 1;
                break;

            default:
                break;
            }
            return(Json(address.Value, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public async Task <NotificationManageViewModel> GetNotificationManage(int?type, int?to)
        {
            var notificationTypes = await _notificationService.GetNotificationTypes();

            var model       = NotificationTypeMapper.ToNotificationManageViewModel(notificationTypes, type, to, JwtTokenProvider.GetUserModelCurrentLanguage(Request.Cookies["token"].Value));
            var appSettings = await _prepareService.GetAllAppSettings();

            model.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;
            }
            if (type != null)
            {
                var notifTypeSetting = notificationTypes.SingleOrDefault(nt => (int)nt.NotificationCategory == type.Value)?.NotificationTypeSetting;
                if (notifTypeSetting != null)
                {
                    model.CanSendMail &= !string.IsNullOrEmpty(notifTypeSetting.Recipients);
                }
            }
            return(model);
        }