//takes the required values and add route related information to database
 public static string AddRoute(string From, string To, int Cost)
 {
     try
     {
         var b = from L in d.Route_Table
                 where L.From.ToUpper() == From.ToUpper() && L.To.ToUpper() == To.ToUpper()
                 select L;
         if (b.Count() > 0)
         {
             return("route already exists");
         }
         int rid = (from r in d.Route_Table
                    select r).Count() + 1;
         Route_Table Rt = new Route_Table();
         Rt.Route_ID = "R" + string.Format("{0:000}", rid);
         Rt.From     = From;
         Rt.To       = To;
         Rt.Cost     = Cost;
         d.Route_Table.Add(Rt);
         d.SaveChanges();
         return("Route details from " + Rt.From + " to " + Rt.To + " added . Route ID is" + Rt.Route_ID);
     }
     catch (DbUpdateException E)
     {
         SqlException ex = E.GetBaseException() as SqlException;
         if (ex.Message.Contains("PK_Route_Table"))
         {
             return("Route id already exists");
         }
     }
     return(null);
 }
        //takes ticket id as input and cancels the booking by removing required column in booking table
        //increments the available tickets
        //returns confirmation as a string with calculated refund item with respect to hours left to booking
        public static string CancelTicket(string bookid)
        {
            try
            {
                double amountRefund;
                var    r = from L in d.Booking_Table
                           where L.Ticket_ID == bookid
                           select L;
                Booking_Table B   = r.FirstOrDefault();
                string        sid = B.SID;
                int           not = B.NoOfTickets;

                var s = from L1 in d.Schedule_Table
                        where L1.SID == sid
                        select L1;
                Schedule_Table S         = s.FirstOrDefault();
                string         rid       = S.Route_ID;
                DateTime       dateOT    = S.DateOfJourney;
                int            timeOT    = int.Parse(S.StartTime.Hours.ToString());
                DateTime       todaydate = DateTime.Now;
                int            age       = (int)(dateOT.Subtract(todaydate).TotalHours);
                int            hoursLeft = age + timeOT;
                var            rt        = from L2 in d.Route_Table
                                           where L2.Route_ID == rid
                                           select L2;
                Route_Table R          = rt.FirstOrDefault();
                int         cost       = R.Cost;
                int         TicketCost = cost * not;
                if (hoursLeft >= 48)
                {
                    amountRefund = TicketCost - (0.1 * TicketCost);
                }
                else if (hoursLeft < 48 && hoursLeft >= 24)
                {
                    amountRefund = TicketCost - (0.25 * TicketCost);
                }
                else if (hoursLeft < 24 && hoursLeft >= 12)
                {
                    amountRefund = TicketCost - (0.5 * TicketCost);
                }
                else
                {
                    amountRefund = TicketCost - (1 * TicketCost);
                }
                S.AvailableSeats = S.AvailableSeats + not;
                d.SaveChanges();
                d.Booking_Table.Remove(B);
                d.SaveChanges();
                return("Tickets Cancelled Successfully. Refund of Amount Rs:" + amountRefund + " inititated to Customer");
            }
            catch (DbUpdateException E)
            {
                SqlException ex = E.GetBaseException() as SqlException;
            }
            return(null);
        }