Here, in this article, I am going to explain the functionality of an online booking engine like we have in goibibo, yatra.com etc. In this project, you can book your airline ticket, can see your booking history, can make notifications, and can copy your previous travel details.

I developed this application by using ASP.NET, C#, SQL Server, JavaScript, & jQuery. Now, I am going to explain the database.

Below is my table’s explanation.

Table 1# Employee (To keep information of registered user)



Table 2# BookingDetail (To keep booking information)



Table 3# Airport (To keep Airport information)



Table 4# Carrier (To keep Airline and their country information)



Given below is the Script file of my Database.
  1. /****** Object: Table [dbo].[Employee] Script Date: 11/19/2016 14:04:23 ******/
  2. SET ANSI_NULLS ON
  3. GO
  4. SET QUOTED_IDENTIFIER ON
  5. GO
  6. SET ANSI_PADDING ON
  7. GO
  8. CREATE TABLE [dbo].[Employee](
  9. [EMP_CODE] [int] IDENTITY(1,1) NOT NULL,
  10. [Email] [varchar](500) NOT NULL,
  11. [First_Name] [varchar](50) NOT NULL,
  12. [Last_Name] [varchar](50) NULL,
  13. [Password] [varchar](50) NOT NULL,
  14. [Supervisor_Code] [varchar](500) NULL,
  15. [DOB] [varchar](50) NULL,
  16. [PreferredCarrier] [varchar](200) NULL,
  17. CONSTRAINT [PK_Employee] PRIMARY KEY CLUSTERED
  18. (
  19. [EMP_CODE] ASC,
  20. [Email] ASC
  21. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  22. ) ON [PRIMARY]
  23. GO
  24. SET ANSI_PADDING OFF
  25. GO
  26. /****** Object: Table [dbo].[Carrier] Script Date: 11/19/2016 14:04:23 ******/
  27. SET ANSI_NULLS ON
  28. GO
  29. SET QUOTED_IDENTIFIER ON
  30. GO
  31. SET ANSI_PADDING ON
  32. GO
  33. CREATE TABLE [dbo].[Carrier](
  34. [CarrierID] [int] IDENTITY(1,1) NOT NULL,
  35. [Airline] [varchar](500) NULL,
  36. [Country] [varchar](50) NULL,
  37. CONSTRAINT [PK_Carrier] PRIMARY KEY CLUSTERED
  38. (
  39. [CarrierID] ASC
  40. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  41. ) ON [PRIMARY]
  42. GO
  43. SET ANSI_PADDING OFF
  44. GO
  45. /****** Object: Table [dbo].[BookingDetail] Script Date: 11/19/2016 14:04:23 ******/
  46. SET ANSI_NULLS ON
  47. GO
  48. SET QUOTED_IDENTIFIER ON
  49. GO
  50. SET ANSI_PADDING ON
  51. GO
  52. CREATE TABLE [dbo].[BookingDetail](
  53. [Booking_ID] [int] IDENTITY(1,1) NOT NULL,
  54. [Emp_Code] [varchar](500) NOT NULL,
  55. [Source] [varchar](50) NULL,
  56. [Destination] [varchar](50) NULL,
  57. [Travelling_Date] [varchar](50) NULL,
  58. [NoOfPassenger] [int] NOT NULL,
  59. [Booking_Date] [varchar](50) NULL,
  60. [TravelClass] [varchar](10) NULL,
  61. [PreferredCarrier] [varchar](100) NULL,
  62. [Remarks] [text] NULL,
  63. CONSTRAINT [PK_BookingDetail] PRIMARY KEY CLUSTERED
  64. (
  65. [Booking_ID] ASC
  66. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  67. ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  68. GO
  69. SET ANSI_PADDING OFF
  70. GO
  71. /****** Object: Table [dbo].[Airport] Script Date: 11/19/2016 14:04:23 ******/
  72. SET ANSI_NULLS ON
  73. GO
  74. SET QUOTED_IDENTIFIER ON
  75. GO
  76. SET ANSI_PADDING ON
  77. GO
  78. CREATE TABLE [dbo].[Airport](
  79. [AirportID] [int] IDENTITY(1,1) NOT NULL,
  80. [AirportCD] [varchar](50) NULL,
  81. [AirportName] [varchar](50) NULL,
  82. CONSTRAINT [PK_Airport] PRIMARY KEY CLUSTERED
  83. (
  84. [AirportID] ASC
  85. )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  86. ) ON [PRIMARY]
  87. GO
  88. SET ANSI_PADDING OFF
  89. GO
Now, open Visual Studio and create a new project. I am going to create this project as a three-layer application.
  1. R-AirlineBookingEngine.DAL
  2. R-AirlineBookingEngine.Models
  3. R-AirlineBookingEngine.Web


In R-AirlineBookingEngine.DAL project, I have added the Entity Framework with the name of TravelTrker.edmx.



Here, I am going to expose the Database Entity with my own Request/Response Model. So, I added an interface and its class here.

IUnitOfWork.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Data;
  7. using System.Collections.Generic;
  8. using ROnlineBookingEngine.Models.ROnlineBookingEngine1;
  9. namespace ROnlineBookingEngine.DAL.UnitOfWork
  10. {
  11. public interface IUnitOfWork
  12. {
  13. string validateLogin(string email, string password);
  14. string NewRegistration(string email, string password, string firstName,
  15. string lastName, string supervisorCode, string dob, string preferedCarrier);
  16. List<BookingHistory> ManageBooking(string TravelType, string Source,string Destination,
  17. string TxtDepartDate, string TxtReturnDate, int TxtNoOfTravellers, string TravelClass,
  18. string UserID, string Remarks);
  19. List<BookingHistory> BindBookingHistory(string UserID);
  20. string GetSupervisorInformation(string prefix);
  21. List<KeyValuePair<string, string>> GetPreferedCarrier(string prefix);
  22. List<KeyValuePair<string, string>> GetSourceDestination(string prefix);
  23. }
  24. }


UnitOfWork.cs
  1. using ROnlineBookingEngine.Models.ROnlineBookingEngine1;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net.Mail;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Web;
  10. namespace ROnlineBookingEngine.DAL.UnitOfWork
  11. {
  12. public class UnitOfWork : IUnitOfWork
  13. {
  14. private TravelTrackerEntities context = null;
  15. public UnitOfWork()
  16. {
  17. context = new TravelTrackerEntities();
  18. }
  19. public string validateLogin(string email, string password)
  20. {
  21. UserLogin loginView = new UserLogin();
  22. using (TravelTrackerEntities context = new TravelTrackerEntities())
  23. {
  24. var query = from a in context.Employee.Where(rec => rec.Email.Equals(email) && rec.Password.Equals(password))
  25. select new
  26. {
  27. a.EMP_CODE,
  28. a.First_Name,
  29. a.Last_Name,
  30. a.Supervisor_Code,
  31. a.Email
  32. };
  33. if (query != null)
  34. {
  35. if (query.Count() > 0)
  36. return "Login Success-" + query.FirstOrDefault().First_Name + " " + query.FirstOrDefault().Last_Name;
  37. }
  38. }
  39. return "Login Failed";
  40. }
  41. public string NewRegistration(string email, string password, string firstName, string lastName, string supervisorCode, string dob, string preferedCarrier)
  42. {
  43. using (TravelTrackerEntities context = new TravelTrackerEntities())
  44. {
  45. var query = from a in context.Employee.Where(rec => rec.Email.Equals(email) && rec.Password.Equals(password))
  46. select new
  47. {
  48. a.EMP_CODE,
  49. a.First_Name,
  50. a.Last_Name,
  51. a.Supervisor_Code,
  52. a.Email
  53. };
  54. if (query != null)
  55. {
  56. if (query.Count() > 0)
  57. {
  58. return "User already exist";
  59. }
  60. else
  61. {
  62. Employee emp = new Employee();
  63. &nbisp;emp.Email = email;
  64. emp.Password = password;
  65. emp.First_Name = firstName;
  66. emp.Last_Name = lastName;
  67. emp.Supervisor_Code = supervisorCode;
  68. emp.DOB = dob;
  69. emp.PreferredCarrier = preferedCarrier;
  70. context.Employee.Add(emp);
  71. context.SaveChanges();
  72. return "Registration Success";
  73. }
  74. }
  75. }
  76. return "Registration Failed";
  77. }
  78. public List<BookingHistory> ManageBooking(string TravelType, string Source, string Destination, string TxtDepartDate, string TxtReturnDate, int TxtNoOfTravellers, string TravelClass, string UserID, string Remarks)
  79. {
  80. List<BookingHistory> details = new List<BookingHistory>();
  81. using (TravelTrackerEntities context = new TravelTrackerEntities())
  82. {
  83. var query = from a in context.Employee.Where(rec => rec.Email.Equals(UserID))
  84. select new
  85. {
  86. a.EMP_CODE,
  87. a.First_Name,
  88. a.Last_Name,
  89. a.Supervisor_Code,
  90. a.Email
  91. };
  92. if (query != null)
  93. {
  94. if (query.Count() > 0)
  95. {
  96. BookingDetail book = new BookingDetail();
  97. book.Emp_Code = UserID;
  98. book.Source = Source;
  99. book.Destination = Destination;
  100. book.Travelling_Date = TxtDepartDate;
  101. book.NoOfPassenger = TxtNoOfTravellers;
  102. book.Booking_Date = System.DateTime.Now.ToString();
  103. book.TravelClass = TravelClass;
  104. book.Remarks = Remarks;
  105. context.BookingDetail.Add(book);
  106. context.SaveChanges();
  107. if (TravelType == "Round Trip")
  108. {
  109. BookingDetail bookReturn = new BookingDetail();
  110. bookReturn.Emp_Code = UserID;
  111. bookReturn.Source = Destination;
  112. bookReturn.Destination = Source;
  113. bookReturn.Travelling_Date = TxtReturnDate;
  114. bookReturn.NoOfPassenger = TxtNoOfTravellers;
  115. bookReturn.Booking_Date = System.DateTime.Now.ToString();
  116. bookReturn.TravelClass = TravelClass;
  117. bookReturn.Remarks = Remarks;
  118. context.BookingDetail.Add(bookReturn);
  119. context.SaveChanges();
  120. }
  121. //Getting Supervisor Informaiton
  122. //======================================
  123. int SuperVisorCode = Convert.ToInt32(query.FirstOrDefault().Supervisor_Code);
  124. var supervisorInfo = from a in context.Employee.Where(rec => rec.EMP_CODE.Equals(SuperVisorCode))
  125. select new
  126. {
  127. a.EMP_CODE,
  128. a.First_Name,
  129. a.Last_Name,
  130. a.Supervisor_Code,
  131. a.Email
  132. };
  133. string supervisorName = supervisorInfo.FirstOrDefault().First_Name + " " + supervisorInfo.FirstOrDefault().Last_Name;
  134. string bookUserName = query.FirstOrDefault().First_Name + " " + query.FirstOrDefault().Last_Name;
  135. string supervisorEmail = supervisorInfo.FirstOrDefault().Email;
  136. SendMail(supervisorName, bookUserName, supervisorEmail, Source, Destination, TxtDepartDate);
  137. //======================================
  138. }
  139. }
  140. //==========================================================================================
  141. var bookingHistory = from a in context.BookingDetail.Where(rec => rec.Emp_Code.Equals(UserID))
  142. select new
  143. {
  144. a.Booking_ID,
  145. a.Emp_Code,
  146. a.Source,
  147. a.Destination,
  148. a.Travelling_Date,
  149. a.NoOfPassenger,
  150. a.Booking_Date,
  151. a.TravelClass
  152. };
  153. foreach (var item in bookingHistory)
  154. {
  155. BookingHistory bookObj = new BookingHistory();
  156. bookObj.Booking_ID = item.Booking_ID;
  157. bookObj.Emp_Code = item.Emp_Code;
  158. bookObj.Source = item.Source;
  159. bookObj.Destination = item.Destination;
  160. bookObj.Travelling_Date = item.Travelling_Date;
  161. bookObj.NoOfPassenger = item.NoOfPassenger;
  162. bookObj.Booking_Date = item.Booking_Date;
  163. bookObj.TravelClass = item.TravelClass;
  164. details.Add(bookObj);
  165. }
  166. }
  167. return details;
  168. }
  169. public List<BookingHistory> BindBookingHistory(string UserID)
  170. {
  171. List<BookingHistory> details = new List<BookingHistory>();
  172. using (TravelTrackerEntities context = new TravelTrackerEntities())
  173. {
  174. var bookingHistory = from a in context.BookingDetail.Where(rec => rec.Emp_Code.Equals(UserID))
  175. select new
  176. {
  177. a.Booking_ID,
  178. a.Emp_Code,
  179. a.Source,
  180. a.Destination,
  181. a.Travelling_Date,
  182. a.NoOfPassenger,
  183. a.Booking_Date,
  184. a.TravelClass
  185. };
  186. foreach (var item in bookingHistory)
  187. {
  188. BookingHistory bookObj = new BookingHistory();
  189. bookObj.Booking_ID = item.Booking_ID;
  190. bookObj.Emp_Code = item.Emp_Code;
  191. bookObj.Source = item.Source;
  192. bookObj.Destination = item.Destination;
  193. bookObj.Travelling_Date = item.Travelling_Date;
  194. bookObj.NoOfPassenger = item.NoOfPassenger;
  195. bookObj.Booking_Date = item.Booking_Date;
  196. bookObj.TravelClass = item.TravelClass;
  197. details.Add(bookObj);
  198. }
  199. }
  200. return details;
  201. }
  202. public void SendMail(string SupervisorName, string name, string supervisorEmail, string source, string destination, string travellingDate)
  203. {
  204. try
  205. {
  206. //Sending Mail
  207. MailMessage mail = new MailMessage();
  208. mail.To.Add(supervisorEmail);
  209. mail.From = new MailAddress("[email protected]");
  210. mail.Subject = "New Ticket Booking";
  211. string Body = MailBody(SupervisorName, name, source, destination, travellingDate);
  212. mail.Body = Body;
  213. mail.IsBodyHtml = true;
  214. SmtpClient smtp = new SmtpClient();
  215. smtp.Host = "smtp.gmail.com";
  216. smtp.Port = 587;
  217. smtp.UseDefaultCredentials = false;
  218. smtp.Credentials = new System.Net.NetworkCredential
  219. ("[email protected]", "Password");// Enter seders User name and password
  220. smtp.EnableSsl = true;
  221. smtp.Send(mail);
  222. }
  223. catch (Exception ex)
  224. {
  225. }
  226. }
  227. public string MailBody(string SupervisorName, string name, string source, string destination, string travellingDate)
  228. {
  229. StreamReader reader = new StreamReader(HttpContext.Current.Server.MapPath("~/MailContent.html"));
  230. string readFile = reader.ReadToEnd();
  231. string StrContent = "";
  232. StrContent = readFile;
  233. StrContent = StrContent.Replace("[MyName]", SupervisorName).Replace("[UserName]", name).Replace("[Source]", source).Replace("[Destination]", destination).Replace("[TravelDate]", travellingDate);
  234. return StrContent;
  235. }
  236. public string GetSupervisorInformation(string prefix)
  237. {
  238. string record = string.Empty;
  239. int SuperVisorCode = Convert.ToInt32(prefix);
  240. using (TravelTrackerEntities context = new TravelTrackerEntities())
  241. {
  242. var matches = from m in context.Employee
  243. where m.EMP_CODE.Equals(SuperVisorCode)
  244. select new
  245. {
  246. m.First_Name,
  247. m.Email
  248. };
  249. foreach (var item in matches)
  250. {
  251. record = item.First_Name + "-" + item.Email;
  252. }
  253. }
  254. return record;
  255. }
  256. public List<KeyValuePair<string, string>> GetPreferedCarrier(string prefix)
  257. {
  258. var list = new List<KeyValuePair<string, string>>();
  259. using (TravelTrackerEntities context = new TravelTrackerEntities())
  260. {
  261. var matches = from m in context.Carrier
  262. where m.Airline.StartsWith(prefix)
  263. select new
  264. {
  265. m.CarrierID,
  266. m.Airline,
  267. m.Country
  268. };
  269. foreach (var item in matches)
  270. {
  271. list.Add(new KeyValuePair<string, string>(item.Airline.ToString(), item.Country));
  272. }
  273. }
  274. return list;
  275. }
  276. public List<KeyValuePair<string, string>> GetSourceDestination(string prefix)
  277. {
  278. var list = new List<KeyValuePair<string, string>>();
  279. using (TravelTrackerEntities context = new TravelTrackerEntities())
  280. {
  281. var matches = from m in context.Airport
  282. where m.AirportName.StartsWith(prefix)
  283. select new
  284. {
  285. m.AirportName,
  286. m.AirportCD
  287. };
  288. foreach (var item in matches)
  289. {
  290. list.Add(new KeyValuePair<string, string>(item.AirportName.ToString(), item.AirportCD));
  291. }
  292. }
  293. return list;
  294. }
  295. }
  296. }
Below is my Mail Content Page.
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>R- Airline Booking Engine</title>
  5. </head>
  6. <body>
  7. <table style="font-family:Calibri;background:#E6E6E6">
  8. <tr>
  9. <td>
  10. <p>Dear [SupervisorName]</p>
  11. <p>[UserName] booked a new ticket from [Source] to [Destination]
  12. using R- Airline Booking Engine.</p>
  13. <p>Travel Date [TravelDate]</p>
  14. </td>
  15. </tr>
  16. <tr>
  17. <td>
  18. Thanks & Regards,
  19. [email protected]
  20. </td>
  21. </tr>
  22. </table>
  23. </body>
  24. </html>
Now, I am going to explain the working of my project. When you run this project, the login page will appear.



Registration Page



After making registration or login, you will be redirected to Booking airline page. Here, in source and destination, I am using auto suggestion feature.









After this, the message page will redirect to booking history page.



From here, you can copy any previous ticket and you can also set reminder. Now, I am showing how the data is storing in my tables.