Esempio n. 1
0
        public IHttpActionResult GetFlights()
        {
            try
            {
                IList <FlightViewModel> flights = null;

                using (var ctx = new BookingFlightEntities())
                {
                    flights = (from flight in ctx.Flights
                               select new FlightViewModel
                    {
                        FlightName = flight.FlightName,
                        TotalSeats = flight.TotalSeats,
                        Id = flight.Id,
                        FlightId = flight.Id,
                        FlightIdTobeCanceled = flight.Id
                    }).Distinct().ToList <FlightViewModel>();
                }

                if (!flights.Any())
                {
                    return(NotFound());
                }

                return(Ok(flights));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 2
0
        public IHttpActionResult DeleteFlightDetail(int id)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest("Not a valid flight id"));
                }

                using (var ctx = new BookingFlightEntities())
                {
                    var flight = ctx.FlightDetails
                                 .Where(s => s.Id == id)
                                 .FirstOrDefault();

                    ctx.Entry(flight).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 3
0
        public IHttpActionResult PutFlight(Flight flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flighttobeUpdated = ctx.Flights.Where(x => x.Id == flight.Id).FirstOrDefault <Flight>();
                    if (flighttobeUpdated != null)
                    {
                        flighttobeUpdated.FlightName = flight.FlightName;
                        flighttobeUpdated.TotalSeats = flight.TotalSeats;
                    }

                    ctx.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 4
0
        public IHttpActionResult PostUser(UserLogin user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }

                using (var ctx = new BookingFlightEntities())
                {
                    ctx.UserLogins.Add(new UserLogin()
                    {
                        UserName   = user.UserName,
                        Password   = user.Password,
                        TypeOfUser = user.TypeOfUser
                    });

                    ctx.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 5
0
        public IHttpActionResult PostFlightScheduleDetail(FlightScheduleDetail flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flights = new FlightScheduleDetail()
                    {
                        JourneyDate      = flight.JourneyDate,
                        Price            = flight.Price,
                        SeatAvailability = flight.SeatAvailability,
                        FlightDetailId   = flight.FlightDetailId
                    };
                    ctx.FlightScheduleDetails.Add(flights);

                    ctx.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 6
0
        public IHttpActionResult PutFlightScheduleDetail(FlightScheduleDetail flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flighttobeUpdated = ctx.FlightScheduleDetails.Where(x => x.Id == flight.Id).FirstOrDefault <FlightScheduleDetail>();
                    if (flighttobeUpdated != null)
                    {
                        flighttobeUpdated.JourneyDate      = flight.JourneyDate;
                        flighttobeUpdated.Price            = flight.Price;
                        flighttobeUpdated.SeatAvailability = flight.SeatAvailability;
                    }

                    ctx.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 7
0
        public IHttpActionResult PostFlight(Flight flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flights = new Flight()
                    {
                        FlightName = flight.FlightName,
                        TotalSeats = flight.TotalSeats
                    };
                    ctx.Flights.Add(flights);

                    ctx.SaveChanges();
                    return(Json(new { id = flights.Id }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IHttpActionResult PutTicketCancellation(int ticketId)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }

                using (var ctx = new BookingFlightEntities())
                {
                    var ticketToBeCancelled = ctx.TicketDetails.Where(x => x.Id == ticketId).FirstOrDefault <TicketDetail>();

                    if (ticketToBeCancelled != null)
                    {
                        ticketToBeCancelled.BookingStatus = BookingStatusValues.Cancelled;
                    }

                    ctx.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 9
0
        public IHttpActionResult PostUserTicketHistory(UserTicketHistory history)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }

                using (var ctx = new BookingFlightEntities())
                {
                    ctx.UserTicketHistories.Add(new UserTicketHistory()
                    {
                        UserLoginId    = history.UserLoginId,
                        TicketDetailId = history.TicketDetailId
                    });

                    ctx.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IHttpActionResult PutFlightdetail(FlightDetail flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flighttobeUpdated = ctx.FlightDetails.Where(x => x.Id == flight.Id).FirstOrDefault <FlightDetail>();
                    if (flighttobeUpdated != null)
                    {
                        flighttobeUpdated.FromCity  = flight.FromCity;
                        flighttobeUpdated.ToCity    = flight.ToCity;
                        flighttobeUpdated.Departure = flight.Departure;
                        flighttobeUpdated.Arrival   = flight.Arrival;
                    }

                    ctx.SaveChanges();
                }
                return(Ok());
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IHttpActionResult PostFlightDetail(FlightDetail flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var flights = new FlightDetail()
                    {
                        FromCity  = flight.FromCity,
                        ToCity    = flight.ToCity,
                        Departure = flight.Departure,
                        Arrival   = flight.Arrival,
                        FlightId  = flight.FlightId
                    };
                    ctx.FlightDetails.Add(flights);

                    ctx.SaveChanges();
                    return(Json(new { id = flights.Id }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 12
0
        //[Route("api/UserLogin/GetUser/{UserName}/{Password}")]
        //public IHttpActionResult GetUser(string UserName, string Password)
        //{
        //    try
        //    {
        //        UserLogin userlogin = null;

        //        using (var ctx = new BookingFlightEntities())
        //        {
        //            userlogin = (from user in ctx.UserLogins
        //                         where user.UserName == UserName && user.Password == Password
        //                         select user).FirstOrDefault();
        //        }
        //        if (userlogin != null)
        //        {
        //            return Json(new { id = userlogin.Id, UserType = userlogin.TypeOfUser });
        //        }
        //        else
        //        {
        //            return Json(new { });
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        throw new Exception(ex.Message);
        //    }
        //}

        //[BasicAuthentication]
        public static bool Login(string UserName, string Password)
        {
            try
            {
                using (var ctx = new BookingFlightEntities())
                {
                    return ctx.UserLogins.Any(user => user.UserName.Equals(UserName, StringComparison.OrdinalIgnoreCase) && user.Password == Password)
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public IHttpActionResult GetFlights()
        {
            try
            {
                IList <FlightDetailViewModel> flights = null;

                CreatioLogin login        = new CreatioLogin("http://*****:*****@gmail.com", "Newuser@1").ToString();

                using (var ctx = new BookingFlightEntities())
                {
                    flights = (from flight in ctx.Flights
                               join flightDetail in ctx.FlightDetails
                               on flight.Id equals flightDetail.FlightId
                               join flightSchedule in ctx.FlightScheduleDetails
                               on flightDetail.Id equals flightSchedule.FlightDetailId
                               select new FlightDetailViewModel
                    {
                        Id = flightSchedule.Id,
                        FlightName = flight.FlightName,
                        Departure = flightDetail.Departure,
                        Arrival = flightDetail.Arrival,
                        JourneyDate = flightSchedule.JourneyDate,
                        FromCity = flightDetail.FromCity,
                        ToCity = flightDetail.ToCity,
                        Price = flightSchedule.Price,
                        SeatAvailability = flightSchedule.SeatAvailability,
                        token = token
                    }).ToList <FlightDetailViewModel>();
                }

                //CreatioLogin login = new CreatioLogin("http://localhost:86/", "Supervisor", "Supervisor");
                // login.TryLogin();

                if (!flights.Any())
                {
                    return(NotFound());
                }

                return(Ok(flights));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 14
0
        public IHttpActionResult DeleteFlightScheduleDetail(int id)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest("Not a valid flight id"));
                }

                using (var ctx = new BookingFlightEntities())
                {
                    var flight = ctx.FlightScheduleDetails
                                 .Where(s => s.Id == id)
                                 .FirstOrDefault();

                    var tickets = from flightdetails in ctx.FlightDetails
                                  join flightschedule in ctx.FlightScheduleDetails
                                  on flightdetails.Id equals flightschedule.FlightDetailId
                                  join ticket in ctx.TicketDetails
                                  on flightschedule.Id equals ticket.FlightScheduleDetailId
                                  where flightschedule.Id == flight.Id &&
                                  ticket.BookingStatus == BookingStatusValues.Confirmed &&
                                  flightschedule.JourneyDate >= DateTime.Now
                                  select ticket;
                    if (tickets.Any())
                    {
                        throw new Exception("Tickets were booked for the flight");
                    }

                    ctx.Entry(flight).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception ex)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.ExpectationFailed)

                {
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(resp);
            }
        }
        public IHttpActionResult GetTicketDetail(string userId)
        {
            try
            {
                IList <TicketDetailViewModel> tickets = null;

                using (var ctx = new BookingFlightEntities())
                {
                    tickets = (from flight in ctx.Flights
                               join flightDetail in ctx.FlightDetails
                               on flight.Id equals flightDetail.FlightId
                               join flightSchedule in ctx.FlightScheduleDetails
                               on flightDetail.Id equals flightSchedule.FlightDetailId
                               join ticket in ctx.TicketDetails
                               on flightDetail.Id equals ticket.FlightScheduleDetailId
                               join history in ctx.UserTicketHistories
                               on ticket.Id equals history.TicketDetailId
                               where userId.Equals(history.UserId) &&
                               ticket.BookingStatus == BookingStatusValues.Confirmed &&
                               flightSchedule.JourneyDate >= DateTime.Now
                               select new TicketDetailViewModel
                    {
                        FlightName = flight.FlightName,
                        JourneyDate = flightSchedule.JourneyDate,
                        FromCity = flightDetail.FromCity,
                        ToCity = flightDetail.ToCity,
                        Price = flightSchedule.Price,
                        PassengerCount = ticket.PassengerCount,
                        TotalFare = ticket.TotalFare,
                        BookingStatus = "Confirmed",
                        Id = ticket.Id
                    }).ToList <TicketDetailViewModel>();
                }

                if (!tickets.Any())
                {
                    return(NotFound());
                }

                return(Ok(tickets));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 16
0
        public IHttpActionResult GetTicketDetailHistory(int userId)
        {
            try
            {
                IList <TicketDetailViewModel> tickets = null;

                using (var ctx = new BookingFlightEntities())
                {
                    tickets = (from flight in ctx.Flights
                               join flightDetail in ctx.FlightDetails
                               on flight.Id equals flightDetail.FlightId
                               join ticket in ctx.TicketDetails
                               on flightDetail.Id equals ticket.FlightDetailId
                               join history in ctx.UserTicketHistories
                               on ticket.Id equals history.TicketDetailId
                               where userId == history.UserLoginId
                               select new TicketDetailViewModel
                    {
                        FlightName = flight.FlightName,
                        JourneyDate = flightDetail.Departure,
                        FromCity = flightDetail.FromCity,
                        ToCity = flightDetail.ToCity,
                        Price = flightDetail.Price,
                        PassengerCount = ticket.PassengerCount,
                        TotalFare = ticket.TotalFare,
                        BookingStatus = ticket.BookingStatus.ToString(),
                        Id = ticket.Id
                    }).Distinct().ToList <TicketDetailViewModel>();
                }

                if (!tickets.Any())
                {
                    return(NotFound());
                }

                return(Ok(tickets));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 17
0
        public IHttpActionResult GetFlightScheduleDetailsByFlightDetailId(int id)
        {
            try
            {
                IList <FlightDetailViewModel> flights = null;

                using (var ctx = new BookingFlightEntities())
                {
                    flights = (from flight in ctx.Flights
                               join flightDetail in ctx.FlightDetails
                               on flight.Id equals flightDetail.FlightId
                               join flightschedule in ctx.FlightScheduleDetails
                               on flightDetail.Id equals flightschedule.FlightDetailId
                               where flightDetail.Id == id
                               select new FlightDetailViewModel
                    {
                        Id = flightschedule.Id,
                        FlightName = flight.FlightName,
                        JourneyDate = flightschedule.JourneyDate,
                        Departure = flightDetail.Departure,
                        Arrival = flightDetail.Arrival,
                        FromCity = flightDetail.FromCity,
                        ToCity = flightDetail.ToCity,
                        Price = flightschedule.Price,
                        SeatAvailability = flightschedule.SeatAvailability,
                        FlightId = flightschedule.Id
                    }).ToList <FlightDetailViewModel>();
                }

                if (!flights.Any())
                {
                    return(NotFound());
                }

                return(Ok(flights));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 18
0
        public IHttpActionResult PostTicketBooking(TicketDetail ticket)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var tickets = new TicketDetail()
                    {
                        BookingStatus    = ticket.BookingStatus,
                        PassengerCount   = ticket.PassengerCount,
                        TotalFare        = ticket.TotalFare,
                        CancellationFare = ticket.CancellationFare,
                        FlightDetailId   = ticket.FlightDetailId
                    };
                    ctx.TicketDetails.Add(tickets);

                    ctx.SaveChanges();

                    var flightdetail = ctx.FlightDetails.Where(x => x.Id == tickets.FlightDetailId).FirstOrDefault();
                    if (flightdetail != null)
                    {
                        flightdetail.SeatAvailability -= tickets.PassengerCount;
                    }

                    ctx.SaveChanges();
                    return(Json(new { id = tickets.Id }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 19
0
        public IHttpActionResult PostFlight(Flight flight)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    if (ctx.Flights.Any(x => x.FlightName == flight.FlightName))
                    {
                        throw new Exception("Flight Name should be unique");
                    }
                    var flights = new Flight()
                    {
                        FlightName = flight.FlightName,
                        TotalSeats = flight.TotalSeats
                    };
                    ctx.Flights.Add(flights);

                    ctx.SaveChanges();
                    return(Json(new { id = flights.Id }));
                }
            }
            catch (Exception ex)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.ExpectationFailed)

                {
                    ReasonPhrase = ex.Message
                };

                throw new HttpResponseException(resp);
            }
        }
        public IHttpActionResult PostTicketBooking(TicketDetail ticket)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }
                using (var ctx = new BookingFlightEntities())
                {
                    var tickets = new TicketDetail()
                    {
                        BookingStatus          = ticket.BookingStatus,
                        PassengerCount         = ticket.PassengerCount,
                        TotalFare              = ticket.TotalFare,
                        CancellationFare       = ticket.CancellationFare,
                        FlightScheduleDetailId = ticket.FlightScheduleDetailId
                    };
                    ctx.TicketDetails.Add(tickets);

                    ctx.SaveChanges();

                    var flightdetail = ctx.FlightScheduleDetails.Where(x => x.Id == tickets.FlightScheduleDetailId).FirstOrDefault();
                    if (flightdetail != null)
                    {
                        flightdetail.SeatAvailability -= tickets.PassengerCount;
                    }

                    ctx.SaveChanges();
                    IList <TicketDetailViewModel> ticketdetails = null;
                    var t = new TicketDetailViewModel();

                    ticketdetails = (from flight in ctx.Flights
                                     join flightDetail in ctx.FlightDetails
                                     on flight.Id equals flightDetail.FlightId
                                     join flightSchedule in ctx.FlightScheduleDetails
                                     on flightDetail.Id equals flightSchedule.FlightDetailId
                                     where flightSchedule.Id == tickets.FlightScheduleDetailId
                                     select new TicketDetailViewModel
                    {
                        FlightName = flight.FlightName,
                        JourneyDate = flightSchedule.JourneyDate,
                        FromCity = flightDetail.FromCity,
                        ToCity = flightDetail.ToCity,
                        Price = flightSchedule.Price,
                        PassengerCount = ticket.PassengerCount,
                        TotalFare = ticket.TotalFare,
                        BookingStatus = ticket.BookingStatus.ToString(),
                        Id = tickets.Id,
                        Departure = flightDetail.Departure,
                        Arrival = flightDetail.Arrival
                    }).ToList <TicketDetailViewModel>();

                    CreatioLogin login        = new CreatioLogin("http://localhost:86/", "Supervisor", "Supervisor");
                    var          loginRequest = login.TryLogin();

                    CreatioLogin logins = new CreatioLogin("http://localhost:86/");
                    logins.CallWebService(loginRequest, ticketdetails);

                    return(Json(new { id = tickets.Id }));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }