public async Task <IActionResult> Add([Bind("Time", "ReminderText")] ReminderAddModel reminderAddModel)
        {
            if (reminderAddModel == null || string.IsNullOrWhiteSpace(reminderAddModel.ReminderText))
            {
                return(BadRequest());
            }

            var remindAt = _dateProvider.In(TimeSpan.FromSeconds(int.Parse(reminderAddModel.Time)));
            await _remindersProvider.AddAsync(new Reminder(remindAt, reminderAddModel.ReminderText));

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public async Task <List <Reminder> > GetTriggerableAndSetTriggeredAsync()
        {
            var now          = _dateProvider.Now;
            var triggerLimit = _dateProvider.In(TimeSpan.FromMinutes(-1));
            var triggerable  = (await _reminders.FindAsync(item => item.CompletedAt == null &&
                                                           item.Date <= now &&
                                                           (item.TriggeredAt == null || item.TriggeredAt < triggerLimit)))
                               .ToList();

            foreach (var reminder in triggerable)
            {
                await MarkAsTriggeredAsync(reminder.Id);
            }

            return(triggerable);
        }