public async Task <ActionResult> CancelTicketConfirm(int id) { Tickets t = ticketService.Get(id); //if (ticket.DateOfDeparture.Date.AddDays(-3).CompareTo(DateTime.Now.Date) < 0) try { ticketService.Cancel(id); String netUserID = User.FindFirst(ClaimTypes.NameIdentifier).Value; Users u = userService.Get(netUserID); var body = "<h3>Hi " + u.FirstName + ", this email in a confirmation of the fact that you canceled a ticket on " + DateTime.Now.ToString("dd/MM/yyyy") + "</h3>"; body += "<h4>You can find a summary of this ticket below</h4>"; string type; if (t.IsBusiness == 1) { type = "Business seat"; } else { type = "Economic seat"; } body += "<hr/>"; body += "<div class='row'>" + "<div class='col-md-4'>" + "<h5>Ticket for " + t.Name + "</h5>" + "</div>" + "</div>" + "<div class='row'>" + "<div class='col-md-4'>" + "<p>Time of departure: " + t.DateOfDeparture.Add(t.Tgv.TimeOfDeparture) + "<br/>" + "Time of arrival: " + t.DateOfDeparture.Add(t.Tgv.TimeOfDeparture).Add(t.Tgv.LineNavigation.Duration) + "</p>" + "</div>" + "</div>" + "<div class='row'>" + "<div class='col-md-4'>" + "<p>" + t.Tgv.LineNavigation.DepartureNavigation.City + " → " + t.Tgv.LineNavigation.DestinationNavigation.City + "</p>" + "</div>" + "</div>" + "<div class='row'>" + "<div class='col-md-4'>" + "<p>Type: " + type + "<br/>" + "Seat: " + t.SeatNumber + "<br/>" + "Price: " + t.Price + "</p>" + "</div>" + "</div>"; EmailSender mail = new EmailSender(); await mail.SendEmailAsync( User.Identity.Name, "Ticket canceled on " + DateTime.Now.ToString("dd/MM/yyyy"), body); return(RedirectToAction("History")); } catch (Exception e) { return(RedirectToAction("ErrorWhileSendingMail")); } }