public async Task <IActionResult> Edit(int id, [Bind("PredsGameId,DateTime,Opponent")] PredsGame predsGame) { var user = await _userManager.GetUserAsync(HttpContext.User); if (user.IsAdmin == true) { if (id != predsGame.PredsGameId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(predsGame); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PredsGameExists(predsGame.PredsGameId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(predsGame)); } return(Redirect("/home")); }
private async Task SendEmail(ApplicationUser user, List <Ticket> tickets, PredsGame game) { emailSecret = Configuration["EmailSecrets:Email"]; password = Configuration["EmailSecrets:Password"]; EmailSettings es = new EmailSettings() { PrimaryDomain = "smtp.gmail.com", PrimaryPort = 587, SecondayDomain = "smtp.gmail.com", SecondaryPort = 587, UsernameEmail = emailSecret, UsernamePassword = password, FromEmail = "*****@*****.**", ToEmail = user.Email }; string email = user.Email; string title = "7Element Tickets"; string body = $"<h2>Dear {user.FirstName} {user.LastName},</h2><br>" + $"<p>Congrats you have won {tickets.Count} tickets:</p><br><ol>"; for (int i = 0; i < tickets.Count; i++) { body += $"<li>Section {tickets[i].Section} Row {tickets[i].Row} Seat {tickets[i].Seat}</li>"; } body += $"</ol><p>For the Nashville Predators game on the {game.DateTime} vs the {game.Opponent}. </p><br>" + "<h3>Thank you,</h3>" + "<h2>7Element</h2>"; AuthMessageSender ams = new AuthMessageSender(Options.Create(es)); await ams.SendEmailAsync(email, title, body); }
public async Task <IActionResult> Create([Bind("PredsGameId,DateTime,Opponent")] PredsGame predsGame) { var user = await _userManager.GetUserAsync(HttpContext.User); if (user.IsAdmin == true) { if (ModelState.IsValid) { predsGame.Open = true; _context.Add(predsGame); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(predsGame)); } return(Redirect("/home")); }