Ejemplo n.º 1
0
        public IActionResult Create()
        {
            List <Plant>         plants = context.Plants.ToList();
            AddReminderViewModel addReminderViewModel = new AddReminderViewModel(plants);

            return(View(addReminderViewModel));
        }
Ejemplo n.º 2
0
        public IActionResult Create(AddReminderViewModel addReminderViewModel)
        {
            if (ModelState.IsValid)
            {
                Plant    thePlant    = context.Plants.Find(addReminderViewModel.PlantId);
                Reminder newReminder = new Reminder
                {
                    Email   = addReminderViewModel.EmailAddress,
                    Message = addReminderViewModel.Message,
                    Time    = addReminderViewModel.ReminderTime,
                    Plant   = thePlant
                };

                context.Reminders.Add(newReminder);
                _backgroundJobClient.Schedule <EmailService>(x => x.SendReminderAsync(newReminder), new
                                                             DateTimeOffset(newReminder.Time));
                context.SaveChanges();

                return(Redirect("/Reminders"));
            }

            return(View(addReminderViewModel));
        }