private void CreateNextTurnNotification(string userId, int gameId, string gameName) { this.Data.Notifications.Add(NotificationDataModel.CreateNotification(gameId, userId, string.Format("It is your turn in game \"{0}\"", gameName), NotificationType.YourTurn)); this.Data.SaveChanges(); }
private void CreateJoinedGameNotification(string userId, int gameId, string gameName, string opponentName) { this.Data.Notifications.Add(NotificationDataModel.CreateNotification(gameId, userId, string.Format("{0} joined your game \"{1}\"", opponentName, gameName), NotificationType.YourTurn)); this.Data.SaveChanges(); }
private void CreateEndGameNotifications(string winningPlayerId, string loosingPlayerId, int gameId, string opponentName, string gameName) { this.Data.Notifications.Add(NotificationDataModel.CreateNotification(gameId, winningPlayerId, string.Format("You beat {0} in game \"{1}\"", opponentName, gameName), NotificationType.GameWon)); this.Data.Notifications.Add(NotificationDataModel.CreateNotification(gameId, loosingPlayerId, string.Format("{0} beat you in game in game \"{1}\"", opponentName, gameName), NotificationType.GameLost)); this.Data.SaveChanges(); }
/// <summary> /// All Person Notifications /// </summary> /// <returns></returns> // GET: Notifications public async Task <IActionResult> Index() { var vm = new NotificationDataModel(); vm.Notifications = await _bll.Notifications.AllImportant(User.UserId()); vm.UnreadMessages = (await _bll.Notifications.AllImportant(User.UserId())) .Count(n => n.Status == false); return(View(vm)); }
private NotificationUserModel Map(NotificationDataModel data) { return(new NotificationUserModel { Id = data.Id, OwnerId = data.OwnerId, Text = data.Text, TransactionId = data.TransactionId }); }
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()); } }
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(); }
public async Task SendNotificationDirectByUserId(int notificationCodeId, int userId, MainNotificationTemplateModel mainNotificationTemplateModel) { string output = JsonConvert.SerializeObject(mainNotificationTemplateModel); MainNotificationTemplateModel mainView = JsonConvert.DeserializeObject <MainNotificationTemplateModel>(output); var userNotificationSetting = await _iNotificationQuerie.GetNotificationSettingByUserId(notificationCodeId, userId); if (userNotificationSetting == null) { return; } var role = _httpContextAccessor.HttpContext.User.UserRole(); var idmUsers = await _idmProxy.GetEmployeeDetailsByRoleName(role); var userDataFromIDM = idmUsers.FirstOrDefault(s => s.userId == userId); var userNotificationsModel = new UserNotificationSettingModel { UserId = userNotificationSetting.UserProfileId.Value, Email = userDataFromIDM != null ? userDataFromIDM.email : userNotificationSetting.User.Email, Mobile = userDataFromIDM != null ? userDataFromIDM.mobileNumber : 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) { await SendOneEmail(new EmailModel { Body = template.Email.Body, Subject = template.Email.Title, To = new List <string> { userNotificationsModel.Email } }); } if (userNotificationSetting.Sms) { await SendOneSms(new SmsModel { Body = template.SMS.Body, To = new List <string> { userNotificationsModel.Mobile } }); } }
private async Task <NotificationDataModel> BuildNotificationTemplate(bool isArabic, int TemplateId, NotificationArguments notificationArguments) { var OperationCodes = await _cache.GetOrCreateAsync("OperationCodesList", async entry => { int seconds = int.Parse(_configuration.ChachingConfiguration.CachingMinutes); entry.SlidingExpiration = TimeSpan.FromSeconds(seconds); return(await _iNotificationQuerie.FindAllNotificationOperationCode()); }); var Template = OperationCodes.FirstOrDefault(w => w.NotificationOperationCodeId == TemplateId); NotificationDataModel notificationDataModel = new NotificationDataModel(); notificationDataModel.Email.Body = ReplaceKeysWithValues((isArabic ? Template.EmailBodyTemplateAr : Template.EmailBodyTemplateEn), notificationArguments.BodyEmailArgs); notificationDataModel.Email.Title = ReplaceKeysWithValues((isArabic ? Template.EmailSubjectTemplateAr : Template.EmailSubjectTemplateEn), notificationArguments.SubjectEmailArgs); notificationDataModel.SMS.Body = ReplaceKeysWithValues((isArabic ? Template.SmsTemplateAr : Template.SmsTemplateEn), notificationArguments.SMSArgs); notificationDataModel.PanelMessage = ReplaceKeysWithValues((isArabic ? Template.PanelTemplateAr : Template.PanelTemplateEn), notificationArguments.PanelArgs); return(notificationDataModel); }
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(); } }
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()); } }
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); }