| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using Abp.BackgroundJobs;
- using Abp.Dependency;
- using Abp.Domain.Repositories;
- using Abp.Domain.Uow;
- using VberZero.BaseSystem;
- using VberZero.BaseSystem.Users;
- using VberZero.DomainService.Calendar;
- using VberZero.DomainService.Notifications;
- using VberZero.DomainService.Notifications.Data;
- namespace VberZero.BackgroundJobs.CalendarNotify;
- public class CalendarNotifyBackgroundJob : BackgroundJob<CalendarNotifyArg>, ITransientDependency
- {
- public CalendarNotifyBackgroundJob(IRepository<User, long> userRepository, IRepository<SysCalendar> calendarRepository, IAppNotifier appNotifier, ICalendarEmail calendarEmail)
- {
- _userRepository = userRepository;
- _calendarRepository = calendarRepository;
- _appNotifier = appNotifier;
- _calendarEmail = calendarEmail;
- }
- private readonly IAppNotifier _appNotifier;
- private readonly ICalendarEmail _calendarEmail;
- private readonly IRepository<User, long> _userRepository;
- private readonly IRepository<SysCalendar> _calendarRepository;
- [UnitOfWork]
- public override void Execute(CalendarNotifyArg args)
- {
- var calendar = _calendarRepository.FirstOrDefault(a => a.Id == args.CalendarId);
- if (!calendar.IsNotify)
- {
- return;
- }
- var user = _userRepository.FirstOrDefault(a => a.Id == args.UserId);
- if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.All))
- {
- SystemNotify(user, calendar);
- EmailNotify(user, calendar);
- PhoneNotify(user, calendar);
- }
- else
- {
- if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.System))
- {
- SystemNotify(user, calendar);
- }
- if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.Email))
- {
- EmailNotify(user, calendar);
- }
- if (calendar.NotifyTypes.Contains(VzDefinition.CalendarNotifyType.Phone))
- {
- PhoneNotify(user, calendar);
- }
- }
- }
- private void SystemNotify(User user, SysCalendar calendar)
- {
- _appNotifier.SendCalendarNotifyAsync(user, new CalendarNotificationData(calendar.Title, calendar.Description, calendar.Id));
- }
- private void EmailNotify(User user, SysCalendar calendar)
- {
- _calendarEmail.SendCalendarNotifyAsync(user, calendar);
- }
- private void PhoneNotify(User user, SysCalendar calendar)
- {
- }
- }
|