using System; using System.Data; using System.Linq; using Kreta.Core.MessageBroker.Contract.MobileNotification; using Kreta.Core.MessageBroker.Contract.MobileNotification.Enum; using Kreta.DataAccessManual; using Kreta.Framework.Util; using Kreta.MessageBroker.Client.MobileNotification; using Kreta.Resources; using Serilog; using Serilog.Core.Enrichers; namespace Kreta.Job.Tasks.Helpers.Notification { internal static class FeljegyzesNotificationHelper { /// INFO @DevKornel: Mobil használja internal static void SendFeljegyzesNotification(string connectionString) { var logger = Log.ForContext(new PropertyEnricher[] { new PropertyEnricher("LoggerId", Guid.NewGuid()) }); Dal.ServiceSystemConnection.Run(connectionString, h => { var dal = h.Feljegyzes(); try { var entities = dal.GetAllSchemaFeljegyzesNotification(); dal.SetFeljegyzesAsKikuldott(entities.Select(x => x.FeljegyzesId).Distinct()); MobileNotificationMessage[] mobileNotificationMessages = entities.Select(entity => MobileNotificationMessageHelper.CreateMessage( entity.IntezmenyAzonosito, entity.TanuloId, MobileNotificationMessageType.Note, entity.FeljegyzesId, string.Format(NotificationResource.FeljegyzesNotificationMessage, entity.TanuloNev, entity.TipusId.GetItemNameFromCache(entity.TanevId, entity.IntezmenyAzonosito)), NotificationResource.FeljegyzesTitle)).ToArray(); if (mobileNotificationMessages.Length > 0) { MobileNotificationMessageHelper.PostStudentNotification(mobileNotificationMessages); } } catch (Exception ex) { logger.Fatal(ex, ex.GetType().FullName); } }); } } }