Ejemplo n.º 1
0
        public void Should_Update_SMS_Second()
        {
            NotificationSMS notificationSMS = new NotificationSMS(userId, currentMobile, content, notificationSettingId, link);

            notificationSMS.Update(content);
            Assert.Equal(content, notificationSMS.Content);
        }
Ejemplo n.º 2
0
        public void Should_Update_SMS()
        {
            NotificationSMS notificationSMS = new NotificationSMS(userId, currentMobile, content, notificationSettingId, link);

            notificationSMS.Update(NotifacationStatus.Send);
            Assert.Equal((int)NotifacationStatus.Send, notificationSMS.NotifacationStatusId);
        }
Ejemplo n.º 3
0
        public void Should_Construct_NotificationSMS()
        {
            NotificationSMS notificationSMS = new NotificationSMS(userId, currentMobile, content, notificationSettingId, link);

            _ = new NotificationSMS();

            notificationSMS.ShouldNotBeNull();
        }
Ejemplo n.º 4
0
        private async Task SendNotificationForUsers(QueryResult <EmployeeIntegrationModel> idmUsers, List <UserNotificationSetting> userNotificationSettings, MainNotificationTemplateModel mainNotificationTemplateModel)
        {
            try
            {
                string output = JsonConvert.SerializeObject(mainNotificationTemplateModel);
                MainNotificationTemplateModel mainView = JsonConvert.DeserializeObject <MainNotificationTemplateModel>(output);

                var userNotificationsModel = userNotificationSettings.Select(x => new UserNotificationSettingModel {
                    UserId = x.UserProfileId.Value, Email = idmUsers.Items.Where(i => i.userId == x.User.Id).FirstOrDefault().email, Mobile = idmUsers.Items.Where(i => i.userId == x.User.Id).FirstOrDefault().mobileNumber
                }).ToList();

                var  entityKey             = TempletKey(mainView.EntityValue, mainView.EntityType);
                bool IsNullEmailFirstArrgs = string.IsNullOrEmpty(Convert.ToString(mainView.Args.BodyEmailArgs[0]));
                bool IsNullSmsmFirstArrgs  = string.IsNullOrEmpty(Convert.ToString(mainView.Args.SMSArgs[0]));
                NotificationEmail email;
                NotificationSMS   sms;
                NotificationPanel panel;
                foreach (var setting in userNotificationSettings)
                {
                    if (IsNullEmailFirstArrgs)
                    {
                        mainView.Args.BodyEmailArgs[0] = Convert.ToString(setting.User.FullName);
                    }
                    if (IsNullSmsmFirstArrgs)
                    {
                        mainView.Args.SMSArgs[0] = Convert.ToString(setting.User.FullName);
                    }
                    NotificationDataModel template = await BuildNotificationTemplate(userNotificationSettings.FirstOrDefault().IsArabic, userNotificationSettings.FirstOrDefault().NotificationCodeId, mainView.Args);

                    if (setting.Email)
                    {
                        email = new NotificationEmail(setting.UserProfileId.Value, userNotificationsModel.FirstOrDefault(u => u.UserId == setting.UserProfileId.Value).Email, template.Email.Title, template.Email.Body, setting.Id, mainView.Link, entityKey);
                        await _notifayCommands.AddNotifayWithOutSave(email);
                    }
                    if (setting.Sms)
                    {
                        sms = new NotificationSMS(setting.UserProfileId.Value, userNotificationsModel.FirstOrDefault(u => u.UserId == setting.UserProfileId.Value).Mobile, template.SMS.Body, setting.Id, mainView.Link, entityKey);
                        await _notifayCommands.AddNotifayWithOutSave(sms);
                    }
                    panel = new NotificationPanel(setting.UserProfileId.Value, template.PanelMessage, template.PanelMessage, setting.Id, mainView.Link, mainView.BranchId, mainView.CommitteeId, entityKey);
                    await _notifayCommands.AddNotifayWithOutSave(panel);
                }
                if (userNotificationSettings.Count > 0)
                {
                    await _notifayCommands.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Ejemplo n.º 5
0
        public List <BaseNotification> getBaseNotification()
        {
            NotificationEmail       notificationEmail = new NotificationEmail(1, "*****@*****.**", "testTitle", "TestContent", 1, "link", "key");
            List <BaseNotification> baseNotifications = new List <BaseNotification>();

            baseNotifications.Add(notificationEmail);

            NotificationSMS notificationSMS = new NotificationSMS(1, "0533286913", "content", 1, "link", "key");

            baseNotifications.Add(notificationEmail);
            baseNotifications.Add(notificationSMS);
            return(baseNotifications);
        }
Ejemplo n.º 6
0
        public async Task SendNotificationByUserId(int notificationCodeId, int userId, string userName, MainNotificationTemplateModel mainNotificationTemplateModel)
        {
            string output = JsonConvert.SerializeObject(mainNotificationTemplateModel);
            MainNotificationTemplateModel mainView = JsonConvert.DeserializeObject <MainNotificationTemplateModel>(output);
            var userNotificationSetting            = await _iNotificationQuerie.GetNotificationSettingByUserId(notificationCodeId, userId);

            var entityKey = TempletKey(mainView.EntityValue, mainView.EntityType);

            if (userNotificationSetting == null)
            {
                return;
            }
            var userDataFromIDM = await _idmProxy.GetUserbyUserName(userName);

            var userNotificationsModel = new UserNotificationSettingModel
            {
                UserId = userNotificationSetting.UserProfileId.Value,
                Email  = userDataFromIDM != null ? userDataFromIDM.Email : userNotificationSetting.User.Email,
                Mobile = userDataFromIDM != null ? userDataFromIDM.PhoneNumber : userNotificationSetting.User.Mobile,
            };
            bool IsNullEmailFirstArrgs = string.IsNullOrEmpty(Convert.ToString(mainView.Args.BodyEmailArgs[0]));
            bool IsNullSmsmFirstArrgs  = string.IsNullOrEmpty(Convert.ToString(mainView.Args.SMSArgs[0]));

            if (IsNullEmailFirstArrgs)
            {
                mainView.Args.BodyEmailArgs[0] = Convert.ToString(userNotificationSetting.User.FullName);
            }
            if (IsNullSmsmFirstArrgs)
            {
                mainView.Args.SMSArgs[0] = Convert.ToString(userNotificationSetting.User.FullName);
            }
            NotificationDataModel template = await BuildNotificationTemplate(userNotificationSetting.IsArabic, userNotificationSetting.NotificationCodeId, mainView.Args);

            if (userNotificationSetting.Email)
            {
                var email = new NotificationEmail(userId, userNotificationsModel.Email, template.Email.Title, template.Email.Body, userNotificationSetting.Id, mainView.Link, entityKey);
                await _notifayCommands.AddNotifayWithOutSave(email);
            }
            if (userNotificationSetting.Sms)
            {
                var sms = new NotificationSMS(userNotificationSetting.UserProfileId.Value, userNotificationsModel.Mobile, template.SMS.Body, userNotificationSetting.Id, mainView.Link, entityKey);
                await _notifayCommands.AddNotifayWithOutSave(sms);
            }
            var panel = new NotificationPanel(userNotificationSetting.UserProfileId.Value, template.PanelMessage, template.PanelMessage, userNotificationSetting.Id, mainView.Link, mainView.BranchId, mainView.CommitteeId, entityKey);
            await _notifayCommands.AddNotifayWithOutSave(panel);

            await _notifayCommands.SaveChangesAsync();
        }
Ejemplo n.º 7
0
        public async Task SendNotificationByEmailAndSmsForRolesChanged(int userId, string email, string mobileNumber)
        {
            if (!string.IsNullOrEmpty(email))
            {
                var emailObj = new NotificationEmail(userId, email, Resources.BranchResources.Messages.EmailSubject, Resources.BranchResources.Messages.EmailBody, null, null);
                await _notifayCommands.AddNotifayWithOutSave(emailObj);

                await _notifayCommands.SaveChangesAsync();
            }

            if (!string.IsNullOrEmpty(mobileNumber))
            {
                var smsObj = new NotificationSMS(userId, mobileNumber, Resources.BranchResources.Messages.EmailBody, null, null, null);
                await _notifayCommands.AddNotifayWithOutSave(smsObj);

                await _notifayCommands.SaveChangesAsync();
            }
        }
Ejemplo n.º 8
0
        public async Task SendNotificationForUsersByRoleNameAndAgency(int notificationCodeId, string roleName, MainNotificationTemplateModel mainNotificationTemplateModel, string AgencyCode, int agencyType, List <int> userIds = null)
        {
            UsersSearchCriteriaModel _usersSearchCriteriaModel = new UsersSearchCriteriaModel()
            {
                RoleName   = roleName,
                AgencyId   = AgencyCode,
                AgencyType = agencyType
            };
            string output = JsonConvert.SerializeObject(mainNotificationTemplateModel);
            MainNotificationTemplateModel mainView = JsonConvert.DeserializeObject <MainNotificationTemplateModel>(output);
            List <int> users = new List <int>();

            if ((userIds?.Count() ?? 0) == 0)
            {
                var idmUsers = await _idmProxy.GetMonafasatUsersByAgencyTypeAndRoleName(_usersSearchCriteriaModel);

                var Users = _mapper.Map <QueryResult <EmployeeIntegrationModel> >(idmUsers);
                users = Users.Items.Select(x => x.userId).ToList();
            }
            else
            {
                users = userIds;
            }

            var userNotificationSettings = await _iNotificationQuerie.GetNotificationSettingByRoleAndOperationCode(users, notificationCodeId);

            if (userNotificationSettings.Count == 0)
            {
                return;
            }
            var userNotificationsModel = userNotificationSettings.Select(x => new UserNotificationSettingModel {
                UserId = x.UserProfileId.Value, Email = x.User.Email, Mobile = x.User.Mobile
            }).ToList();
            var  entityKey             = TempletKey(mainView.EntityValue, mainView.EntityType);
            bool IsNullEmailFirstArrgs = string.IsNullOrEmpty(Convert.ToString(mainView.Args.BodyEmailArgs[0]));
            bool IsNullSmsmFirstArrgs  = string.IsNullOrEmpty(Convert.ToString(mainView.Args.SMSArgs[0]));
            NotificationEmail email;
            NotificationSMS   sms;
            NotificationPanel panel;

            foreach (var setting in userNotificationSettings)
            {
                if (IsNullEmailFirstArrgs)
                {
                    mainView.Args.BodyEmailArgs[0] = Convert.ToString(setting.User.FullName);
                }
                if (IsNullSmsmFirstArrgs)
                {
                    mainView.Args.SMSArgs[0] = Convert.ToString(setting.User.FullName);
                }
                NotificationDataModel template = await BuildNotificationTemplate(userNotificationSettings.FirstOrDefault().IsArabic, userNotificationSettings.FirstOrDefault().NotificationCodeId, mainView.Args);

                if (setting.Email)
                {
                    email = new NotificationEmail(setting.UserProfileId.Value, userNotificationsModel.FirstOrDefault(u => u.UserId == setting.UserProfileId.Value).Email, template.Email.Title, template.Email.Body, setting.Id, mainView.Link, entityKey);
                    await _notifayCommands.AddNotifayWithOutSave(email);
                }
                if (setting.Sms)
                {
                    sms = new NotificationSMS(setting.UserProfileId.Value, userNotificationsModel.FirstOrDefault(u => u.UserId == setting.UserProfileId.Value).Mobile, template.SMS.Body, setting.Id, mainView.Link, entityKey);
                    await _notifayCommands.AddNotifayWithOutSave(sms);
                }
                panel = new NotificationPanel(setting.UserProfileId.Value, template.PanelMessage, template.PanelMessage, setting.Id, mainView.Link, mainView.BranchId, mainView.CommitteeId, entityKey);
                await _notifayCommands.AddNotifayWithOutSave(panel);
            }
            if (userNotificationSettings.Count > 0)
            {
                await _notifayCommands.SaveChangesAsync();
            }
        }
Ejemplo n.º 9
0
        private async Task SendNotificationForUsers(int notificationCodeId, int branchId, int?committeeId, MainNotificationTemplateModel mainNotificationTemplateModel)
        {
            try
            {
                string output = JsonConvert.SerializeObject(mainNotificationTemplateModel);
                MainNotificationTemplateModel mainView = JsonConvert.DeserializeObject <MainNotificationTemplateModel>(output);
                var oldUserNotificationSettings        = await _iNotificationQuerie.GetNotificationSettingByUserIdAndUserType(notificationCodeId, branchId, (committeeId ?? 0));

                if (oldUserNotificationSettings.Count == 0)
                {
                    return;
                }
                string UserRole      = ((Enums.UserRole)oldUserNotificationSettings[0].UserRoleId).ToString();
                var    agencyDetails = new GovAgency();
                if (branchId != 0)
                {
                    agencyDetails = await _BranchQuery.GetAgencyCodeByBranchId(branchId);
                }
                else if (committeeId != null && committeeId != 0)
                {
                    agencyDetails = await _CommitteeQuery.FindAgencyCodeByCommitteeId(committeeId);
                }
                var agencyCode = agencyDetails != null ? agencyDetails.AgencyCode : "";
                var agencyType = agencyDetails != null ? agencyDetails.CategoryId : 0;
                UsersSearchCriteriaModel _usersSearchCriteriaModel = new UsersSearchCriteriaModel()
                {
                    RoleName   = UserRole,
                    AgencyId   = agencyCode,
                    PageSize   = 1000,
                    AgencyType = agencyType ?? 0
                };
                var idmUsers = await _idmProxy.GetMonafasatUsersByAgencyTypeAndRoleName(_usersSearchCriteriaModel);

                var        Users = _mapper.Map <QueryResult <EmployeeIntegrationModel> >(idmUsers);
                List <int> users = Users.Items.Select(x => x.userId).ToList();
                var        userNotificationSettings = await _iNotificationQuerie.GetNotificationSettingByRoleAndOperationCode(users, notificationCodeId, branchId, committeeId);

                var userNotificationsModel = userNotificationSettings.Select(x => new UserNotificationSettingModel {
                    UserId = x.UserProfileId.Value, Email = idmUsers.Items.Where(i => i.userId == x.User.Id).FirstOrDefault().email, Mobile = idmUsers.Items.Where(i => i.userId == x.User.Id).FirstOrDefault().mobileNumber
                }).ToList();
                var  entityKey             = TempletKey(mainView.EntityValue, mainView.EntityType);
                bool IsNullEmailFirstArrgs = string.IsNullOrEmpty(Convert.ToString(mainView.Args.BodyEmailArgs[0]));
                bool IsNullSmsmFirstArrgs  = string.IsNullOrEmpty(Convert.ToString(mainView.Args.SMSArgs[0]));
                NotificationEmail email;
                NotificationSMS   sms;
                NotificationPanel panel;
                foreach (var setting in userNotificationSettings)
                {
                    if (IsNullEmailFirstArrgs)
                    {
                        mainView.Args.BodyEmailArgs[0] = Convert.ToString(setting.User.FullName);
                    }
                    if (IsNullSmsmFirstArrgs)
                    {
                        mainView.Args.SMSArgs[0] = Convert.ToString(setting.User.FullName);
                    }
                    NotificationDataModel template = await BuildNotificationTemplate(userNotificationSettings.FirstOrDefault().IsArabic, userNotificationSettings.FirstOrDefault().NotificationCodeId, mainView.Args);

                    if (setting.Email)
                    {
                        email = new NotificationEmail(setting.UserProfileId.Value, userNotificationsModel.FirstOrDefault(u => u.UserId == setting.UserProfileId.Value).Email, template.Email.Title, template.Email.Body, setting.Id, mainView.Link, entityKey);
                        await _notifayCommands.AddNotifayWithOutSave(email);
                    }
                    if (setting.Sms)
                    {
                        sms = new NotificationSMS(setting.UserProfileId.Value, userNotificationsModel.FirstOrDefault(u => u.UserId == setting.UserProfileId.Value).Mobile, template.SMS.Body, setting.Id, mainView.Link, entityKey);
                        await _notifayCommands.AddNotifayWithOutSave(sms);
                    }
                    panel = new NotificationPanel(setting.UserProfileId.Value, template.PanelMessage, template.PanelMessage, setting.Id, mainView.Link, mainView.BranchId, mainView.CommitteeId, entityKey);
                    await _notifayCommands.AddNotifayWithOutSave(panel);
                }
                if (userNotificationSettings.Count > 0)
                {
                    await _notifayCommands.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.ToString());
            }
        }
Ejemplo n.º 10
0
        public async Task <bool> SendNotificationForSuppliers(int notificationCodeId, List <string> crsList, MainNotificationTemplateModel mainNotificationTemplateModel, Dictionary <string, Dictionary <int, string> > dynamicParameterList = null)
        {
            string output = JsonConvert.SerializeObject(mainNotificationTemplateModel);
            MainNotificationTemplateModel mainView = JsonConvert.DeserializeObject <MainNotificationTemplateModel>(output);
            List <CRNotificationModel>    crs      = new List <CRNotificationModel>();

            if (crsList.Any())
            {
                var idmContacts = await _idmProxy.GetContactOfficersByCR(crsList);

                crs = idmContacts.Items.AsEnumerable().Select(x => new CRNotificationModel
                {
                    CR     = x.supplierNumber,
                    Mobile = x.mobile,
                    Email  = x.email
                }).ToList();
            }
            var userNotificationSettings = await _iNotificationQuerie.GetNotificationSettingByCrAndOperationCode(crs.Select(x => x.CR).ToList(), notificationCodeId);

            if (userNotificationSettings.Count == 0)
            {
                return(true);
            }
            var  entityKey             = TempletKey(mainView.EntityValue, mainView.EntityType);
            bool IsNullEmailFirstArrgs = string.IsNullOrEmpty(Convert.ToString(mainView.Args.BodyEmailArgs[0]));
            bool IsNullSmsmFirstArrgs  = string.IsNullOrEmpty(Convert.ToString(mainView.Args.SMSArgs[0]));
            NotificationEmail email;
            NotificationSMS   sms;
            NotificationPanel panel;

            foreach (var setting in userNotificationSettings)
            {
                if (IsNullEmailFirstArrgs)
                {
                    mainView.Args.BodyEmailArgs[0] = setting.Supplier.SelectedCrName;
                }
                if (IsNullSmsmFirstArrgs)
                {
                    mainView.Args.SMSArgs[0] = setting.Supplier.SelectedCrName;
                }
                if (dynamicParameterList != null)
                {
                    foreach (var newValue in dynamicParameterList[setting.Cr])
                    {
                        mainView.Args.BodyEmailArgs[newValue.Key] = newValue.Value;
                    }
                }
                NotificationDataModel template = await BuildNotificationTemplate(userNotificationSettings.FirstOrDefault().IsArabic, userNotificationSettings.FirstOrDefault().NotificationCodeId, mainView.Args);

                var ContactOfficer = crs.Where(a => a.CR == setting.Cr).ToList();
                foreach (var currentCR in ContactOfficer)
                {
                    if (setting.Email)
                    {
                        email = new NotificationEmail(setting.Cr, currentCR.Email, template.Email.Title, template.Email.Body, setting.Id, mainView.Link, entityKey);
                        await _notifayCommands.AddNotifayWithOutSave(email);
                    }
                    if (setting.Sms)
                    {
                        sms = new NotificationSMS(setting.Cr, currentCR.Mobile, template.SMS.Body, setting.Id, mainView.Link, entityKey);
                        await _notifayCommands.AddNotifayWithOutSave(sms);
                    }
                }
                panel = new NotificationPanel(setting.Cr, template.PanelMessage, template.PanelMessage, setting.Id, mainView.Link, mainView.BranchId, mainView.CommitteeId, entityKey);
                await _notifayCommands.AddNotifayWithOutSave(panel);
            }
            if (userNotificationSettings.Count > 0)
            {
                await _notifayCommands.SaveChangesAsync();
            }
            return(true);
        }
Ejemplo n.º 11
0
        public void Should_Construct_NotificationSMS_Fourth()
        {
            NotificationSMS notificationSMS = new NotificationSMS(cr, currentMobile, content, notificationSettingId, link, key);

            notificationSMS.ShouldNotBeNull();
        }