Esempio n. 1
0
        public async Task <IActionResult> Create(
            [Bind("Id,Url")] RecurringAlert recurringAlert)
        {
            if (ModelState.IsValid)
            {
                recurringAlert.CreatedOn         = DateTime.Now;
                recurringAlert.ApplicationUserId = _userManager.GetUserId(HttpContext.User);
                recurringAlert.EmailAddress      = (await _userManager.GetUserAsync(HttpContext.User)).Email;
                _context.Add(recurringAlert);
                await _context.SaveChangesAsync();

                _alertingService.AddJob(recurringAlert.Url, recurringAlert.EmailAddress);
                BackgroundJob.Enqueue(
                    () => AlertingService.NewUserConfirmation(recurringAlert.Url, recurringAlert.EmailAddress));
                return(RedirectToAction("Index"));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Set <ApplicationUser>(), "Id", "Id",
                                                           recurringAlert.ApplicationUserId);
            return(View(recurringAlert));
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("Id,EmailAddress,CreatedOn,Url,ApplicationUserId")] RecurringAlert recurringAlert)
        {
            if (id != recurringAlert.Id)
            {
                return(NotFound());
            }

            if (recurringAlert.ApplicationUserId != _userManager.GetUserId(HttpContext.User))
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(recurringAlert);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RecurringAlertExists(recurringAlert.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Set <ApplicationUser>(), "Id", "Id",
                                                           recurringAlert.ApplicationUserId);
            return(View(recurringAlert));
        }