public ActionResult Create([Bind(Include = "Id,LName,FName,EmployedDate")] Staff staff)
        {
            if (ModelState.IsValid)
            {
                db.Staffs.Add(staff);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(staff));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Origin")] Airline airline)
        {
            if (ModelState.IsValid)
            {
                db.Airline.Add(airline);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(airline));
        }
        public ActionResult Create([Bind(Include = "Id,Code,DestPlace,FlightDate")] Flight flight)
        {
            if (ModelState.IsValid)
            {
                db.Flights.Add(flight);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(flight));
        }
Example #4
0
        public ActionResult Create([Bind(Include = "Id,LName,FName,EnrolmentDate")] Client client)
        {
            if (ModelState.IsValid)
            {
                db.Clients.Add(client);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(client));
        }
Example #5
0
        public bool DeleteMealById(int Id)
        {
            bool status = false;
            var  meal   = GetMealById(Id);

            meal.IsActive = false;
            try
            {
                _airlineContext.SaveChanges();
                status = true;
            }
            catch { }
            return(status);
        }
Example #6
0
 public void AddUser(string username, string email, string password)
 {
     context.Users.Add(new User {
         Username = username, Email = email, Password = password, RoleId = 3
     });
     context.SaveChanges();
 }
Example #7
0
        public ActionResult Create([Bind(Include = "Id,Name,NameAlias,FriendlyName,DisplayName,DbName,SSRSFolder")] Airline airlineModels)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    context.Airline.Add(airlineModels);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }

            return(View(airlineModels));
        }
Example #8
0
        //Update race
        public static void UpdateRace(int raceID, int raceTeamID)
        {
            AirlineContext db = new AirlineContext();
            Race           a  = db.Races.Find(raceID);

            a.RaceTeamID = raceTeamID;
            db.SaveChanges();
        }
Example #9
0
        static void Main(string[] args)
        {
            //Country c = new Country { Name="Serbia" };
            AirlineContext context = new AirlineContext();

            context.SaveChanges();
            context.Dispose();
        }
Example #10
0
        //Updating of the stuardesses for RaceTeam
        public static void UpdateStuardesses(int?firstStuardess, int?secondStuardess, int raceTeamID)
        {
            AirlineContext db = new AirlineContext();

            RaceTeam b = db.RaceTeams.Include(i => i.Stuardesses).FirstOrDefault(i => i.ID == raceTeamID);

            b.Stuardesses.Clear();
            db.SaveChanges();
            Stuardess a = db.Stuardesses.FirstOrDefault(i => i.ID == firstStuardess);

            if (a != null)
            {
                b.Stuardesses.Add(a);
                db.SaveChanges();
            }
            a = db.Stuardesses.FirstOrDefault(i => i.ID == secondStuardess);
            if (a != null)
            {
                b.Stuardesses.Add(a);
                db.SaveChanges();
            }
        }
Example #11
0
        public bool Register(Users users)
        {
            bool status = false;

            try
            {
                _airlineContext.Users.Add(users);
                _airlineContext.SaveChanges();
                status = true;
            }
            catch (Exception ex)
            {
            }
            return(status);
        }
Example #12
0
        public async Task <IActionResult> resetPassword(int id, User user)
        {
            var editPassword = await _context.Users.SingleOrDefaultAsync(r => r.ID == user.ID);

            if (editPassword != null)
            {
                if (ModelState.IsValid)
                {
                    string password = Crypto.HashPassword(user.Password);
                    editPassword.Password = password;
                    _context.Entry(editPassword).State = EntityState.Modified;
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(View());
        }
Example #13
0
 public async Task <int> AddFligth(FlightRaw model)
 {
     _context.Flight.Add(model);
     return(_context.SaveChanges());
 }
Example #14
0
 public int SaveChanges()
 {
     return(Db.SaveChanges());
 }
 public void Commit()
 {
     context.SaveChanges();
 }
        public async Task Handle(CarNotReserved message, IMessageHandlerContext context)
        {
            log.Info($"Received CarNotReserved, CombinedReservationId = ");

            //oslobodi sjedista

            foreach (var seatRes in message.tickets)
            {
                List <Airline> companies = _context.AirlineCompanies
                                           .Include(comp => comp.FastTickets)
                                           .Include(comp => comp.Destinations)
                                           .Include(comp => comp.PopDestinaations)
                                           .Include(comp => comp.Raters)
                                           .Include(comp => comp.Flights).ThenInclude(f => f.Luggage)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.From)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.To)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.Stops)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.AllTickets)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.Seats).ThenInclude(d => d.Traveller)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                           .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                           .ToList();

                foreach (var u in companies)
                {
                    foreach (var u2 in u.Flights)
                    {
                        foreach (var u3 in u2.Seats)
                        {
                            if (seatRes.Item1 == u3.Id)
                            {
                                u3.Taken = false;
                                _context.SaveChanges();
                            }
                        }
                    }
                }

                foreach (var c in companies)
                {
                    foreach (var f in c.Flights)
                    {
                        foreach (var rez in f.AllTickets)
                        {
                            if (rez.userId == message.userId)
                            {
                                if (rez.Id == seatRes.Item2)
                                {
                                    rez.userId  = "-1";
                                    rez.reqTick = "-1";
                                    _context.SaveChanges();
                                }
                            }
                        }
                    }
                }
            }

            SeatNotReserved seatNotReserved = new SeatNotReserved();

            seatNotReserved.userId = message.userId;
            seatNotReserved.resId  = message.resId;
            seatNotReserved.combinedReservationId = message.combinedReservationId;
            await context.Publish(seatNotReserved).ConfigureAwait(false);
        }
        public static void SeedAirlines(AirlineContext con)
        {
            if (con.AirlineCompanies.Count() != 0)
            {
                return;
            }
            Airline airline = new Airline();

            Destination d1 = new Destination();

            d1.Name        = "Belgrade";
            d1.Description = "The capital and largest city of Serbia. It is located at the confluence of the Sava and Danube";
            d1.Img         = "belgrade.jpg";
            Destination d2 = new Destination();

            d2.Name        = "Paris";
            d2.Description = "Paris contains the most visited monuments in the city, including the Notre Dame Cathedral and the Louvre as well as the Sainte-Chapelle and the Eiffel Tower.";
            d2.Img         = "paris.jpg";
            Destination d3 = new Destination();

            d3.Name        = "Banja Luka";
            d3.Description = "The city lies on the Vrbas River and is well known in the countries of the former Yugoslavia for being full of tree-lined avenues, boulevards, gardens, and parks.";
            d3.Img         = "banjaluka.jpg";

            Destination d4 = new Destination();

            d4.Name        = "London";
            d4.Description = "London is considered to be one of the  most important global cities and has been called the most powerful, most desirable, most influential and most visited city.";
            d4.Img         = "london.jpg";

            airline.Lat          = 45.254410;
            airline.Lon          = 19.842550;
            airline.Name         = "Serbian air";
            airline.FastTickets  = new List <Ticket>();
            airline.Raters       = new List <Rater>();
            airline.Address      = "Belgrade, Serbia";
            airline.Description  = "Svi direktni letovi kompanije Air Serbia Beograd na jednom mestu. Ukoliko želite direktno da letite za Pariz, Amasterdam, Njujork, Tivat, Rim, Milano i druge evropske gradove Air Serbia je pravi izbor za vas!";
            airline.Destinations = new List <Destination>();
            airline.Destinations.Add(d1);
            airline.Destinations.Add(d2);
            airline.Destinations.Add(d3);
            airline.Destinations.Add(d4);
            airline.Img    = "air-serbia.jpg";
            airline.Rating = 0;

            Flight flight = new Flight();

            /* flight.SoldTickets = new List<Ticket>();
             * flight.Extra = "Perfect your flight experience with full-flat seats, special food offers and other privileges.";
             * flight.Luggage = new Luggage() { Dimensions = "20x30", Quantity = 200, Weight = 122 };
             * flight.Rate = 0;
             * flight.Raters = new List<Rater>();
             * flight.IdCompany = "Serbian air";
             * flight.Trip = Trip.One_way;
             * flight.Seats = new List<Seat>();
             * flight.From = d1;
             * flight.To = d2;
             * flight.DepartureDate = "10.29.1203";
             *
             * flight.NumOfPassengers = 300;
             * flight.Price = 300;
             * flight.Duration = "2";
             * flight.Stops = new List<Destination>();
             *
             *
             * Seat s1 = new Seat();
             * s1.Type = Classes.First;
             * s1.Traveller = new Traveller();
             * s1.Taken = true;
             * s1.IsSelected = false;
             *
             * Seat s2 = new Seat();
             * s2.Type = Classes.First;
             * s2.Traveller = new Traveller();
             * s2.Taken = false;
             * s2.IsSelected = false;
             *
             * Seat s3 = new Seat();
             * s3.Type = Classes.First;
             * s3.Traveller = new Traveller();
             * s3.Taken = false;
             * s3.IsSelected = false;
             *
             * Seat s4 = new Seat();
             * s4.Type = Classes.First;
             * s4.Traveller = new Traveller();
             * s4.Taken = false;
             * s4.IsSelected = false;
             *
             * Seat s5 = new Seat();
             * s5.Type = Classes.First;
             * s5.Traveller = new Traveller();
             * s5.Taken = true;
             * s5.IsSelected = false;
             *
             * Seat s6 = new Seat();
             * s6.Type = Classes.First;
             * s6.Traveller = new Traveller();
             * s6.Taken = false;
             * s6.IsSelected = false;
             *
             * Seat s7 = new Seat();
             * s7.Type = Classes.First;
             * s7.Traveller = new Traveller();
             * s7.Taken = false;
             * s7.IsSelected = false;
             *
             * Seat s8 = new Seat();
             * s8.Type = Classes.First;
             * s8.Traveller = new Traveller();
             * s8.Taken = false;
             * s8.IsSelected = false;
             *
             * Seat s9 = new Seat();
             * s9.Type = Classes.Business;
             * s9.Traveller = new Traveller();
             * s9.Taken = false;
             * s9.IsSelected = false;
             *
             * Seat s10 = new Seat();
             * s10.Type = Classes.Business;
             * s10.Traveller = new Traveller();
             * s10.Taken = false;
             * s10.IsSelected = false;
             *
             * Seat s11 = new Seat();
             * s11.Type = Classes.Business;
             * s11.Traveller = new Traveller();
             * s11.Taken = false;
             * s11.IsSelected = false;
             *
             * Seat s12 = new Seat();
             * s12.Type = Classes.Business;
             * s12.Traveller = new Traveller();
             * s12.Taken = true;
             * s12.IsSelected = false;
             *
             * Seat s13 = new Seat();
             * s13.Type = Classes.Economy;
             * s13.Traveller = new Traveller();
             * s13.Taken = true;
             * s13.IsSelected = false;
             *
             * Seat s14 = new Seat();
             * s14.Type = Classes.Economy;
             * s14.Traveller = new Traveller();
             * s14.Taken = true;
             * s14.IsSelected = false;
             *
             * Seat s15 = new Seat();
             * s15.Type = Classes.Economy;
             * s15.Traveller = new Traveller();
             * s15.Taken = true;
             * s15.IsSelected = false;
             *
             * Seat s16 = new Seat();
             * s16.Type = Classes.Economy;
             * s16.Traveller = new Traveller();
             * s16.Taken = true;
             * s16.IsSelected = false;
             *
             *
             * flight.Seats.Add(s1);
             * flight.Seats.Add(s2);
             * flight.Seats.Add(s3);
             * flight.Seats.Add(s4);
             * flight.Seats.Add(s5);
             * flight.Seats.Add(s6);
             * flight.Seats.Add(s7);
             * flight.Seats.Add(s8);
             * flight.Seats.Add(s9);
             * flight.Seats.Add(s10);
             * flight.Seats.Add(s11);
             * flight.Seats.Add(s12);
             * flight.Seats.Add(s13);
             * flight.Seats.Add(s14);
             * flight.Seats.Add(s15);
             * flight.Seats.Add(s16);
             */
            airline.Flights = new List <Flight>();
            //airline.Flights.Add(flight);

            con.AirlineCompanies.Add(airline);



            con.SaveChanges();
        }
Example #18
0
        public async Task Handle(ReservationCreated message, IMessageHandlerContext context)
        {
            log.Info($"Received ReservationCreated, CombinedReservationId = {message.combinedReservationId}");

            //napravi rezervaciju za sjedista

            List <Airline> companies = _context.AirlineCompanies
                                       .Include(comp => comp.FastTickets)
                                       .Include(comp => comp.Destinations)
                                       .Include(comp => comp.PopDestinaations)
                                       .Include(comp => comp.Raters)
                                       .Include(comp => comp.Flights).ThenInclude(f => f.Luggage)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.From)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.To)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Stops)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.AllTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Seats).ThenInclude(d => d.Traveller)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.SoldTickets)
                                       .Include(fs => fs.Flights).ThenInclude(d => d.Raters)
                                       .ToList();

            string userid = message.userId;
            int    points = Int32.Parse(message.pointsS);

            Discount dis = new Discount();

            dis.BronzeTier      = message.tickets[0].b;
            dis.SilverTier      = message.tickets[0].s;
            dis.DiscountPercent = message.tickets[0].d;
            dis.GoldTier        = message.tickets[0].g;

            List <Tuple <int, int> > tickets = new List <Tuple <int, int> >();
            int mainSeatId = 0;

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                foreach (var model in message.tickets)
                {
                    foreach (var u in companies)
                    {
                        foreach (var u2 in u.Flights)
                        {
                            foreach (var u3 in u2.Seats)
                            {
                                if (u3.Id == model.seat.Id)  // ako je to sediste iz rezervacije
                                {
                                    if (!u3.Taken)
                                    {
                                        u3.Traveller = new Traveller()
                                        {
                                            Email = model.seat.Traveller.Email, FirstName = model.seat.Traveller.FirstName, IdUser = model.seat.Traveller.IdUser, LastName = model.seat.Traveller.LastName, Passport = model.seat.Traveller.Passport
                                        };
                                        u3.Taken = true;

                                        try
                                        {
                                            _context.SaveChanges();
                                        }
                                        catch (Exception e)
                                        {
                                            await dbContextTransaction.RollbackAsync();

                                            SeatNotReserved resFailed = new SeatNotReserved();
                                            resFailed.combinedReservationId = message.combinedReservationId;
                                            resFailed.userId = message.userId;
                                            resFailed.resId  = message.resId;
                                            await context.Publish(resFailed).ConfigureAwait(false);

                                            return;
                                        }


                                        Ticket t = new Ticket()
                                        {
                                            Discount = 0, Flight = u2, Seat = u3
                                        };

                                        if (userid == model.seat.Traveller.IdUser)
                                        {
                                            t.userId = userid;
                                            if (points > dis.BronzeTier && points < dis.SilverTier)
                                            {
                                                t.Discount = (Int32)(dis.DiscountPercent) + t.Discount;
                                            }

                                            else if (points > dis.SilverTier && points < dis.GoldTier)
                                            {
                                                t.Discount = (Int32)(dis.DiscountPercent * 2) + t.Discount;
                                            }
                                            else
                                            {
                                                t.Discount = (Int32)(dis.DiscountPercent * 3) + t.Discount;
                                            }

                                            if (u2.SoldTickets == null)
                                            {
                                                u2.SoldTickets = new List <SoldTicket>();
                                            }

                                            u2.SoldTickets.Add(new SoldTicket()
                                            {
                                                ticket = t
                                            });
                                            if (u2.AllTickets == null)
                                            {
                                                u2.AllTickets = new List <Ticket>();
                                            }
                                            u2.AllTickets.Add(t);

                                            try
                                            {
                                                _context.SaveChanges();
                                            }
                                            catch (Exception e)
                                            {
                                                await dbContextTransaction.RollbackAsync();

                                                SeatNotReserved resFailed = new SeatNotReserved();
                                                resFailed.combinedReservationId = message.combinedReservationId;
                                                resFailed.userId = message.userId;
                                                resFailed.resId  = message.resId;
                                                await context.Publish(resFailed).ConfigureAwait(false);

                                                return;
                                            }
                                            mainSeatId = t.Id;
                                        }
                                        else
                                        {
                                            t.reqTick = model.seat.Traveller.IdUser;
                                            u2.AllTickets.Add(t);

                                            try
                                            {
                                                _context.SaveChanges();
                                            }
                                            catch (Exception e)
                                            {
                                                await dbContextTransaction.RollbackAsync();

                                                SeatNotReserved resFailed = new SeatNotReserved();
                                                resFailed.combinedReservationId = message.combinedReservationId;
                                                resFailed.userId = message.userId;
                                                resFailed.resId  = message.resId;
                                                await context.Publish(resFailed).ConfigureAwait(false);

                                                return;
                                            }
                                        }
                                        tickets.Add(new Tuple <int, int>(u3.Id, t.Id));
                                        if (message.userId == model.seat.Traveller.IdUser)
                                        {
                                            mainSeatId = t.Id;
                                        }
                                    }
                                    else
                                    {
                                        await dbContextTransaction.RollbackAsync();

                                        SeatNotReserved resFailed = new SeatNotReserved();
                                        resFailed.combinedReservationId = message.combinedReservationId;
                                        resFailed.userId = message.userId;
                                        resFailed.resId  = message.resId;
                                        await context.Publish(resFailed).ConfigureAwait(false);

                                        return;
                                    }
                                }
                            }
                        }
                    }
                }

                await dbContextTransaction.CommitAsync();
            }

            SeatReserved seatReserved = new SeatReserved();

            seatReserved.combinedReservationId = message.combinedReservationId;
            seatReserved.car        = message.car;
            seatReserved.userId     = message.userId;
            seatReserved.pointsS    = message.pointsS;
            seatReserved.tickets    = tickets;
            seatReserved.resId      = message.resId;
            seatReserved.mainSeatId = mainSeatId;
            await context.Publish(seatReserved).ConfigureAwait(false);
        }