public async Task Handle(CarReserved message, IMessageHandlerContext context) { log.Info($"Received CarReserved, CombinedReservationId = {message.combinedReservationId}"); // doda poene korisniku i ako uspije to je kraj, postavi onu rezervaciju na successfull var users = _context.Users.Include(us => us.CombinedReservations).ToList(); string userId = message.userId; var user = await _userManager.FindByIdAsync(userId); user.Points += 10; foreach (var res in user.CombinedReservations) { if (res.Id == message.resId) { res.Status = "Approved"; } } await _userManager.UpdateAsync(user); _context.Update(user); try { _context.SaveChanges(); } catch (Exception e) { foreach (var res in user.CombinedReservations) { if (res.Id == message.resId) { res.Status = "Denied"; await _userManager.UpdateAsync(user); _context.Update(user); _context.SaveChanges(); } } ReservationNotApproved notApproved = new ReservationNotApproved(); notApproved.combinedReservationId = message.combinedReservationId; notApproved.carRes = message.carRes; notApproved.resId = message.resId; notApproved.tickets = message.tickets; notApproved.userId = message.userId; await context.Publish(notApproved).ConfigureAwait(false); } }
public async Task Handle(FlightCancelled message, IMessageHandlerContext context) { log.Info($"Received FlightCancelled"); // doda poene korisniku i ako uspije to je kraj, postavi onu rezervaciju na successfull var users = _context.Users.Include(us => us.CombinedReservations).ToList(); string userId = message.userId; var user = await _userManager.FindByIdAsync(userId); if (user != null) { user.Points -= 5; await _userManager.UpdateAsync(user); _context.Update(user); _context.SaveChanges(); } }
public async Task Handle(SeatNotReserved message, IMessageHandlerContext context) { log.Info($"Received SeatNotReserved, CombinedReservationId = "); // postavi na unsuccessfull, mora da se odradi string userId = message.userId; var users = _context.ApplicationUsers.Include(u => u.CombinedReservations).ToList(); var user = await _userManager.FindByIdAsync(userId); foreach (var res in user.CombinedReservations) { if (res.Id == message.resId) { res.Status = "Denied"; await _userManager.UpdateAsync(user); _context.Update(user); _context.SaveChanges(); return; } } }
public static void SeedCompanies(ApplicationUsersContext context) { if (context.RentACarCompanies.Count() != 0) { return; } Address addr1 = new Address() { FullAddress = "Bulevar Oslobodjenja 81, Novi Sad, Serbia", Latitude = 45.254152, Longitude = 19.836035 }; Address addr2 = new Address() { FullAddress = "Blok 28, Belgrade, Serbia", Latitude = 44.812298, Longitude = 20.417439 }; RentACar company1 = new RentACar(); company1.Activated = true; company1.AvrageRating = 0; company1.Cars = new List <Car>(); company1.Description = "No description"; company1.extras = new List <ExtraAmenity>(); company1.Image = "kompanija1.jpg"; company1.Locations = new List <Address>() { addr1, addr2 }; company1.MainLocation = new Address() { FullAddress = "Vukovarska 2, Belgrade, Serbia", Latitude = 44.792089, Longitude = 20.430300 }; company1.Name = "National Car Rental"; company1.QuickReservations = new List <QuickReservation>(); company1.Ratings = new List <Rating>(); ExtraAmenity amenity1 = new ExtraAmenity(); amenity1.Name = "Additional driver"; amenity1.Image = "addDriver2.png"; amenity1.Price = 100; amenity1.OneTimePayment = false; ExtraAmenity amenity2 = new ExtraAmenity(); amenity2.Name = "GPS Navigation"; amenity2.Image = "GPS2.png"; amenity2.Price = 20; amenity2.OneTimePayment = true; ExtraAmenity amenity3 = new ExtraAmenity(); amenity3.Name = "Unlimited miles"; amenity3.Image = "UnlimitedMiles2.png"; amenity3.Price = 80; amenity3.OneTimePayment = true; ExtraAmenity amenity4 = new ExtraAmenity(); amenity4.Name = "Child & baby seats"; amenity4.Image = "childSeats2.png"; amenity4.Price = 40; amenity4.OneTimePayment = true; ExtraAmenity amenity5 = new ExtraAmenity(); amenity5.Name = "WiFi hotspot device"; amenity5.Image = "wifi2.png"; amenity5.Price = 25; amenity5.OneTimePayment = true; ExtraAmenity amenity6 = new ExtraAmenity(); amenity6.Name = "Car rental protection plan"; amenity6.Image = "protectionPlan2.png"; amenity6.Price = 75; amenity6.OneTimePayment = true; ExtraAmenity amenity7 = new ExtraAmenity(); amenity7.Name = "Prepaid fuel"; amenity7.Image = "fuel2.png"; amenity7.Price = 30; amenity7.OneTimePayment = true; ExtraAmenity amenity8 = new ExtraAmenity(); amenity8.Name = "Extended roadside protection"; amenity8.Image = "roadsideProtection2.png"; amenity8.Price = 65; amenity8.OneTimePayment = true; ExtraAmenity amenity9 = new ExtraAmenity(); amenity9.Name = "Winter tires & snow chains"; amenity9.Image = "snow2.png"; amenity9.Price = 50; amenity9.OneTimePayment = true; ExtraAmenity amenity10 = new ExtraAmenity(); amenity10.Name = "Delivery & collection"; amenity10.Image = "driver2.png"; amenity10.Price = 100; amenity10.OneTimePayment = true; List <ExtraAmenity> amenities = new List <ExtraAmenity>(); amenities.Add(amenity1); amenities.Add(amenity2); amenities.Add(amenity3); amenities.Add(amenity4); amenities.Add(amenity5); amenities.Add(amenity6); amenities.Add(amenity7); amenities.Add(amenity8); amenities.Add(amenity9); amenities.Add(amenity10); company1.extras = amenities; context.RentACarCompanies.Add(company1); context.SaveChanges(); List <RentACar> companies = context.RentACarCompanies.ToList(); Car car1 = new Car(); car1.AvrageRating = 0; car1.Brand = "Ford"; car1.CompanyId = companies[0].ID; car1.Image = "fusion.jpg"; car1.Location = addr1.FullAddress; car1.Model = "Fusion"; car1.Passengers = 5; car1.PricePerDay = 70; car1.Ratings = new List <Rating>(); car1.RentedDates = new List <Date>(); car1.Type = "full-size"; car1.Year = 2015; car1.Removed = false; Car car2 = new Car(); car2.AvrageRating = 0; car2.Brand = "WW"; car2.CompanyId = companies[0].ID; car2.Image = "audia4.jpg"; car2.Location = addr2.FullAddress; car2.Model = "Audi A4"; car2.Passengers = 5; car2.PricePerDay = 85; car2.Ratings = new List <Rating>(); car2.RentedDates = new List <Date>(); car2.Type = "standard-size"; car2.Year = 2015; car2.Removed = false; companies[0].Cars = new List <Car>(); companies[0].Cars.Add(car1); companies[0].Cars.Add(car2); context.RentACarCompanies.Update(companies[0]); context.SaveChanges(); }
public static void SeedAirlines(ApplicationUsersContext 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(); }