Ejemplo n.º 1
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();
        }