Exemplo n.º 1
0
        public async void GenerateEventOfEndActivityAsync()
        {
            var dateOfLastCheckedActivity = await settingsRepository.GetLastActivitySettings();

            var activities = await activityRepository.GetAsync();

            foreach (var activity in activities)
            {
                if (dateOfLastCheckedActivity == null)
                {
                    break;
                }

                if (activity.EndAt.CompareTo(dateOfLastCheckedActivity.DateOfLastCheckedActivity) > 0 &&
                    activity.EndAt.CompareTo(DateTime.Now) < 0)
                {
                    var maraphoneByActivity =
                        await maraphoneRepository.GetAsync(activity.MaraphoneId, CancellationToken.None);

                    var activityFinishedInfo = new ActivityFinishedInfo()
                    {
                        ActivityId  = activity.Id,
                        Title       = maraphoneByActivity.Title,
                        Description = maraphoneByActivity.Description,
                        IsChecked   = false
                    };
                    await activityFinishedInfoRepository.CreateActivityFinishedInfoAsync(activityFinishedInfo);
                }
            }

            var settingOfActivityFinishedInfo = new SettingsEventOfActivity()
            {
                DateOfLastCheckedActivity = DateTime.Now
            };
            await settingsRepository.CreateLastActivitySettings(settingOfActivityFinishedInfo);
        }