public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var ticketList = _context.Tickets.Where(x => x.Seats.Count > 0)
                             .Where(a => a.PurchaseId == id).ToList();
            int sizeoftickets = ticketList.Count();

            for (int i = 0; i < sizeoftickets; i++)
            {
                Ticket t        = ticketList.ElementAt(i);
                var    seatList = _context.Seats
                                  .Where(a => a.TicketId == t.Id).ToList();

                Seat seat = seatList.ElementAt(0);
                seat.TicketId      = null;
                seat.Availability  = true;
                seat.ReservationId = null;
                seat.IsConfirmed   = false;
                _context.Update(seat);
                await _context.SaveChangesAsync();
            }
            var purchase = await _context.Purchases.FindAsync(id);

            String      msg;
            String      userId      = _userManager.GetUserId(HttpContext.User);
            MailAdapter mailAdapter = new MailAdapter();

            msg = "Your ticket is deleted. Here are the refund details \n ";
            msg = msg + "Flight: " + purchase.Tickets.ToList()[0].Flight.Name + "\n" + "Fllght NO : " + purchase.Tickets.ToList()[0].Flight.FlightNo + " \n ";
            msg = msg + "Ticket(s) refunded by refund money of: " + "\n" + purchase.Price * (purchase.Tickets.ToList()[0].Flight.RefundPortion / 100f) + "\n" + "Refunded price will be in your account in 3 to 5 work days.\n\n";
            String to = _context.Users.Where(a => a.Id == userId).Select(a => a.Email).FirstOrDefault().ToString();

            mailAdapter.SendMail(_userManager.GetUserId(HttpContext.User), msg, to);

            _context.Purchases.Remove(purchase);
            await _context.SaveChangesAsync();

            if (User.IsInRole("CompAdmin") && User.IsInRole("WebAdmin"))
            {
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction("Search", "Flights"));
            }
        }
        public IActionResult Purchase(int pId, InputModel inputModel)
        {
            string OwnerId  = _userManager.GetUserId(HttpContext.User);
            var    usercard = _context.CreditCards.Where(x => x.OwnerId == OwnerId).ToList();
            var    cardlist = new SelectList(usercard, "Id", "CardNumber");

            ViewData["CardId"]      = cardlist;
            ViewData["Creditcards"] = "Select a card.";

            var purchase = _context.Purchases.FirstOrDefault(x => x.Id == pId);

            if (purchase == null)
            {
                return(NotFound());
            }

            var ticket = purchase.Tickets.FirstOrDefault(x => x.OwnerId == OwnerId);

            purchase.IsProcessed = true;
            _context.Purchases.Update(purchase);
            _context.SaveChanges();


            //------------------------------------Send Mail Start------------------------------------------//

            String      msg;
            MailAdapter mailAdapter = new MailAdapter();

            msg = "Thank you for your ticket purchase. Here are the details \n ";
            msg = msg + "Flight No : " + ticket.Flight.FlightNo + " \n ";
            msg = msg + "Flight: " + ticket.Flight.Name + "\n" + "Ticket: " + ticket.Id + "\n" + "Price: " + purchase.Price + " TL" + "\n" + "Seat: ";

            //var flt = _context.Flights.Where(a => a.FlightNo.Equals(ticket.Flight.FlightNo)).FirstOrDefault();
            //var tic = _context.Tickets.Where(a => a.EventId.Equals(flt.Id) && a.OwnerId.Equals(OwnerId)).ToList();

            /*
             * foreach(var t in tic)
             *  {
             *  var seat = _context.Seats.Where(a => a.FlightId.Equals(flt.FlightNo) && a.TicketId.Equals(t.Id)).FirstOrDefault();
             *
             *  msg = msg + "Flight: " + ticket.Flight.Name + "\n" + "Ticket: " + "\n" + t.Id + "\n" + "Seat: " + seat.Col + seat.Row + "\n\n";
             * }*/

            var ticket1 = purchase.Tickets.Where(x => x.OwnerId == OwnerId).ToList();

            foreach (var item in ticket1)
            {
                //var seat = _context.Seats.Where(a => a.FlightId.Equals(flt.FlightNo) && a.TicketId.Equals(t.Id)).FirstOrDefault();
                msg = msg + item.Seats.ToArray()[0].Col + item.Seats.ToArray()[0].Row + " ";
                //msg = msg + item.Seats.Col + item.Seats.Row + "\n\n" ;
            }

            String to = _context.Users.Where(a => a.Id == OwnerId).Select(a => a.Email).FirstOrDefault().ToString();

            mailAdapter.SendMail(_userManager.GetUserId(HttpContext.User), msg, to);

            //------------------------------------Send Mail End------------------------------------------//


            return(RedirectToAction(nameof(Successful)));
        }