Beispiel #1
0
 public static void EditAvio(AvioCompanyEditForm form, int id)
 {
     if (form != null)
     {
         using (var _context = new DiemServiceDB())
         {
             AvioCompany retVal = _context.AvioCompanyDbSet.Where(u => u.Id == id)
                                  .Include(x => x.Owner)
                                  .Include(y => y.Flights)
                                  .Include(z => z.Destinations)
                                  .Include(i => i.Address)
                                  .FirstOrDefault();
             string caller = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value;
             User   found  = _context.UserDbSet.Where(u => u.Username == caller).FirstOrDefault();
             if (found.Role != Role.Admin && found.Username != retVal.Owner.Username)
             {
                 return;
             }
             if (form.Name != null)
             {
                 retVal.Name = form.Name;
             }
             if (form.Promo_description != null)
             {
                 retVal.Promo_description = form.Promo_description;
             }
             if (form.Address != null)
             {
                 retVal.Address.State = form.Address;
             }
             _context.SaveChanges();
         }
     }
 }
Beispiel #2
0
 public static void AddFlight(FlightForm flight, int avioId)
 {
     using (var _context = new DiemServiceDB())
     {
         if (flight.FlightClass == 0 || flight.seats == 0 || flight.Flight_Arrival_Time == null || flight.Flight_Departure_Time == null || flight.fromLocation == null || flight.toLocation == null || flight.price == null ||
             flight.Flight_Departure_Time < DateTime.Now ||
             flight.Flight_Departure_Time.Date > flight.Flight_Arrival_Time.Date
             )
         {
             throw new Exception("BAD QEURY");
         }
         string      caller     = ((ClaimsPrincipal)HttpContext.Current.User).FindFirst("username").Value;
         User        loggedUser = _context.UserDbSet.Where(u => u.Username == caller).FirstOrDefault();
         AvioCompany found      = _context.AvioCompanyDbSet.Where(u => u.Id == avioId).Include(x => x.Owner).FirstOrDefault();
         if (loggedUser.Role != Role.Admin && loggedUser.Username != found.Owner.Username)
         {
             return;
         }
         Flight toAdd = flight.toFlight();
         toAdd.To_Location   = _context.LocationDbSet.Add(toAdd.To_Location);
         toAdd.From_Location = _context.LocationDbSet.Add(toAdd.From_Location);
         toAdd.Provider      = found;
         found.Flights.Add(_context.FlightDbSet.Add(toAdd));
         _context.SaveChanges();
     }
 }
Beispiel #3
0
        public static void AddCompany(AddCompanyForm rent)
        {
            using (var _context = new DiemServiceDB())
            {
                User found = _context.UserDbSet.Where(user => user.Username == rent.OwnerUsername).FirstOrDefault();
                switch (found.Role)
                {
                case Role.AdminAvio:
                    AvioCompany toAdd   = rent.getAvio();
                    string      imgName = "avioCompany" + toAdd.Id;
                    File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "/" + imgName, Convert.FromBase64String(toAdd.Logo));
                    toAdd.Logo  = imgName;
                    toAdd.Owner = found;
                    _context.AdminAvioDbSet.Include(x => x.OwnedAvioCompanies)
                    .Where(x => x.Id == found.UlogaID)
                    .FirstOrDefault().OwnedAvioCompanies
                    .Add(_context.AvioCompanyDbSet.Add(toAdd));
                    break;

                case Role.AdminRentACar:
                    RentACar toAdd2 = rent.getRent();
                    toAdd2.Owner = found;
                    _context.AdminRentDbSet.Include(x => x.OwnedRentServices)
                    .Where(x => x.Id == found.UlogaID)
                    .FirstOrDefault().OwnedRentServices
                    .Add(_context.RentACarDbSet.Add(toAdd2));
                    break;

                default:
                    break;
                }

                _context.SaveChanges();
            }
        }
        public async Task <IActionResult> GetCompanyDetails(long id)
        {
            AvioCompanyProfileDTO avioCompanyProfileDTO = new AvioCompanyProfileDTO();

            if (ModelState.IsValid)
            {
                AvioCompany company = await AvioService.GetCompany(id);

                AvioCompanyProfile companyProfile  = new AvioCompanyProfile();
                int avioCompanyRatingPicture       = 0;
                List <Destination> destinationList = company.Destinations;

                string allDestinations = "";
                for (int i = 0; i < destinationList.Count; i++)
                {
                    allDestinations += destinationList[i].Name + ",";
                }

                companyProfile = await AvioService.GetCompanyProfile(id);

                avioCompanyRatingPicture = (int)(Math.Round(await AvioService.GetAverageCompanyRating(id)));

                avioCompanyProfileDTO.Id              = company.AvioCompanyId;
                avioCompanyProfileDTO.Name            = companyProfile.Name;
                avioCompanyProfileDTO.RatingPicture   = avioCompanyRatingPicture;
                avioCompanyProfileDTO.Address         = companyProfile.Address;
                avioCompanyProfileDTO.Description     = companyProfile.PromoDescription;
                avioCompanyProfileDTO.Destinations    = allDestinations;
                avioCompanyProfileDTO.DestinationList = destinationList;

                return(Ok(new { avioCompanyProfileDTO }));
            }
            ModelState.AddModelError("", "Cannot retrieve user data.");
            return(BadRequest(ModelState));
        }
        public async Task <ActionResult <AvioCompany> > PostAvioCompany(AvioCompany avioCompany)
        {
            _context.aviocompanydb.Add(avioCompany);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAvioCompany", new { id = avioCompany.AvioCompanyId }, avioCompany));
        }
        public async Task <IActionResult> PutAvioCompany(int id, AvioCompany avioCompany)
        {
            if (id != avioCompany.AvioCompanyId)
            {
                return(BadRequest());
            }

            _context.Entry(avioCompany).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AvioCompanyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #7
0
        public async Task CreateCompany(AvioCompany company, AvioCompanyProfile profile)
        {
            var result = await _context.AvioCompanyProfiles.AddAsync(profile);

            await _context.SaveChangesAsync();

            long avioCompanyProfileId = result.Entity.AvioCompanyProfileId;

            company.AvioCompanyProfileId = avioCompanyProfileId;
            await _context.AvioCompanies.AddAsync(company);

            await _context.SaveChangesAsync();
        }
Beispiel #8
0
 public static AvioCompany GetById(int id)
 {
     using (var _context = new DiemServiceDB())
     {
         AvioCompany retVal = _context.AvioCompanyDbSet.Where(u => u.Id == id)
                              .Include(x => x.Owner)
                              .Include(y => y.Flights)
                              .Include(y => y.Flights.Select(x => x.To_Location))
                              .Include(y => y.Flights.Select(x => x.From_Location))
                              .Include(y => y.Flights.Select(x => x.Provider))
                              .Include(y => y.Flights.Select(x => x.Transits))
                              .Include(y => y.Flights.Select(x => x.Reservations))
                              .Include("Flights.Reservations.Review")
                              .Include("Flights.Reservations.Review.User")
                              .Include(z => z.Destinations)
                              .Include(i => i.Address)
                              .FirstOrDefault();
         Byte[] img = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "/" + retVal.Logo);
         retVal.Logo = Convert.ToBase64String(img);
         return(retVal);
     }
 }
Beispiel #9
0
 public async Task UpdateCompany(AvioCompany company)
 {
     await _avioRepository.UpdateCompany(company);
 }
Beispiel #10
0
 public async Task CreateCompany(AvioCompany company, AvioCompanyProfile profile)
 {
     await _avioRepository.CreateCompany(company, profile);
 }
Beispiel #11
0
        public async Task <IActionResult> CreateAvioCompany([FromBody] AvioCompanyDTO avioCompanyDTO)
        {
            if (ModelState.IsValid)
            {
                if (await AvioService.CompanyExists(avioCompanyDTO.Name))
                {
                    return(BadRequest("Company already exists with the same name."));
                }

                var profile = new AvioCompanyProfile()
                {
                    Name             = avioCompanyDTO.Name,
                    Address          = avioCompanyDTO.Address,
                    PromoDescription = avioCompanyDTO.Description
                };

                // add destinations
                var dest = new List <Destination>();
                string[,] destinations = { { "Belgrade", "44.786568",  "20.448921"  },
                                           { "Tokyo",    "35.689487",  "139.691711" },
                                           { "New York", "40.712776",  "-74.005974" },
                                           { "Berlin",   "52.520008",  "13.404954"  },
                                           { "Rome",     "41.9028",    "12.4964"    },
                                           { "Zurich",   "47.3768880", "8.541694"   } };

                for (int j = 0; j < destinations.GetLength(0); ++j)
                {
                    Destination destination = new Destination()
                    {
                        Name      = destinations[j, 0],
                        Latitude  = double.Parse(destinations[j, 1], CultureInfo.InvariantCulture),
                        Longitude = double.Parse(destinations[j, 2], CultureInfo.InvariantCulture),
                    };

                    dest.Add(destination);
                }

                AvioCompany company = new AvioCompany()
                {
                    Destinations = dest
                };

                await AvioService.CreateCompany(company, profile);

                // create planes for companies
                var aeroplaneA380 = new Aeroplane()
                {
                    AvioCompanyId = company.AvioCompanyId,
                    Name          = "Airbus A380"
                };

                var aeroplane737 = new Aeroplane()
                {
                    AvioCompanyId = company.AvioCompanyId,
                    Name          = "Boeing 737"
                };

                if (!await AeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplaneA380.Name))
                {
                    await AeroplaneService.AddAeroplane(aeroplaneA380);
                }

                if (!await AeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplane737.Name))
                {
                    await AeroplaneService.AddAeroplane(aeroplane737);
                }

                // create seats for planes
                var seatsA380 = new Seats()
                {
                    AeroplaneId = aeroplaneA380.AeroplaneId,
                    SeatCount   = 240,
                    InOneRow    = 6
                };

                var seats737 = new Seats()
                {
                    AeroplaneId = aeroplane737.AeroplaneId,
                    SeatCount   = 320,
                    InOneRow    = 8
                };

                if (!await SeatService.SeatsExist(aeroplaneA380.AeroplaneId))
                {
                    await SeatService.AddSeats(seatsA380);
                }

                if (!await SeatService.SeatsExist(aeroplane737.AeroplaneId))
                {
                    await SeatService.AddSeats(seats737);
                }

                return(Ok(200));
            }

            return(BadRequest("No sufficient data provided."));
        }
Beispiel #12
0
 public async Task UpdateCompany(AvioCompany avioCompany)
 {
     _context.AvioCompanies.Update(avioCompany);
     await _context.SaveChangesAsync();
 }
        public static async Task AddDefaultAvioCompanies(IServiceProvider serviceProvider, IConfiguration configuration)
        {
            var avioService        = serviceProvider.GetRequiredService <AvioService>();
            var destinationService = serviceProvider.GetRequiredService <DestinationService>();
            var aeroplaneService   = serviceProvider.GetRequiredService <AeroplaneService>();
            var seatService        = serviceProvider.GetRequiredService <SeatService>();

            string[,] avioCompanies = { { "Wizz Air",      "Boulevard of Broken Dreams 33",  "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis arcu et ipsum semper consectetur. Donec sit amet magna augue. Curabitur rhoncus, lacus ut rhoncus pretium, lectus risus sagittis urna, vel imperdiet velit nunc sed sem. Suspendisse ac rutrum neque. Quisque sed mollis enim. Etiam quis eros tempor, dapibus justo eu, blandit libero. Curabitur elementum tincidunt eros ut luctus. Etiam nec felis consequat, tincidunt nisl non, posuere magna. Mauris vel ipsum mauris. Phasellus non ante ornare, tristique est vitae, fringilla odio. Vivamus ultricies lacus et pharetra placerat. Phasellus auctor efficitur sem eget convallis. Sed eu ante sapien. Fusce ac enim in libero rhoncus blandit ut lacinia eros. Sed rhoncus non libero eu hendrerit. Maecenas eget venenatis nisi, vel blandit dolor. "                        },
                                        { "Emirates",      "Boulevard of Awesome Dreams 22", "Aenean consectetur eleifend nulla, ac rutrum turpis vulputate vel. Praesent posuere magna turpis, et tincidunt libero dapibus ac. Nullam euismod felis eget lacus placerat, id fringilla neque sagittis. Curabitur a aliquam ante, quis pharetra tellus. Donec ante dui, sollicitudin quis ex non, tristique tincidunt urna. Duis blandit bibendum ex. In nulla ligula, consectetur quis diam at, laoreet sagittis nisl. Curabitur imperdiet laoreet purus ullamcorper pretium. Pellentesque a sodales nisl, ac laoreet enim. Fusce rhoncus non libero ut tempor. Phasellus eget condimentum sapien, ac fringilla nulla. Duis volutpat tortor ac iaculis faucibus. Aenean dignissim massa dolor, vel efficitur orci molestie a. Cras dignissim molestie nisl, sit amet euismod elit commodo a. Curabitur blandit bibendum fermentum. Fusce vel odio quam." },
                                        { "Qatar Airways", "Damians House 11",               "Phasellus posuere ligula eget mollis hendrerit. Donec finibus orci ut porttitor semper. Ut nec porta augue. Sed libero est, vestibulum tincidunt ipsum eget, laoreet commodo elit. Quisque accumsan aliquam tempus. Ut vestibulum gravida magna, eget semper felis rutrum ornare. In quis lobortis dolor, sed hendrerit velit. Nullam lacinia in nulla non vestibulum. Ut ipsum leo, ullamcorper vel mollis vitae, tempor vitae risus. Maecenas id vulputate purus, id congue erat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Praesent a ullamcorper orci. Duis eu purus feugiat, euismod urna sed, commodo purus. Morbi quis tortor id dui dictum lacinia. Proin porttitor est id turpis pharetra condimentum. Integer at magna nec leo placerat tincidunt sed quis quam. "                           },
                                        { "EVA Air",       "Neverlands Street 44",           "Donec cursus luctus est, malesuada tempor tellus laoreet eget. Vestibulum viverra elit a ex gravida lobortis. Nulla aliquet nunc nec aliquam facilisis. Quisque nec sapien ultricies, tempus leo in, sollicitudin arcu. Integer in gravida ipsum. Maecenas vel ex a quam pulvinar scelerisque ac vel turpis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Pellentesque eleifend sollicitudin velit sed fermentum. Donec congue nisi mi. Suspendisse at facilisis tortor, sagittis mattis justo. Curabitur molestie dictum venenatis. In maximus cursus orci sed iaculis. Praesent posuere vulputate elementum. "                                                                                                                                                                                                } };

            for (int i = 0; i < avioCompanies.GetLength(0); ++i)
            {
                var companyExists = await avioService.CompanyExists(avioCompanies[i, 0]);

                if (!companyExists)
                {
                    AvioCompanyProfile profile = new AvioCompanyProfile()
                    {
                        Name             = avioCompanies[i, 0],
                        Address          = avioCompanies[i, 1],
                        PromoDescription = avioCompanies[i, 2]
                    };

                    // add destinations
                    var dest = new List <Destination>();
                    string[,] destinations = { { "Belgrade", "44.786568",  "20.448921"  },
                                               { "Tokyo",    "35.689487",  "139.691711" },
                                               { "New York", "40.712776",  "-74.005974" },
                                               { "Berlin",   "52.520008",  "13.404954"  },
                                               { "Rome",     "41.9028",    "12.4964"    },
                                               { "Zurich",   "47.3768880", "8.541694"   } };

                    for (int j = 0; j < destinations.GetLength(0); ++j)
                    {
                        Destination destination = new Destination()
                        {
                            Name      = destinations[j, 0],
                            Latitude  = double.Parse(destinations[j, 1], CultureInfo.InvariantCulture),
                            Longitude = double.Parse(destinations[j, 2], CultureInfo.InvariantCulture),
                        };

                        dest.Add(destination);
                    }

                    AvioCompany company = new AvioCompany()
                    {
                        Destinations = dest
                    };

                    await avioService.CreateCompany(company, profile);

                    // create planes for companies
                    var aeroplaneA380 = new Aeroplane()
                    {
                        AvioCompanyId = company.AvioCompanyId,
                        Name          = "Airbus A380"
                    };

                    var aeroplane737 = new Aeroplane()
                    {
                        AvioCompanyId = company.AvioCompanyId,
                        Name          = "Boeing 737"
                    };

                    if (!await aeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplaneA380.Name))
                    {
                        await aeroplaneService.AddAeroplane(aeroplaneA380);
                    }

                    if (!await aeroplaneService.AeroplaneExists(company.AvioCompanyId, aeroplane737.Name))
                    {
                        await aeroplaneService.AddAeroplane(aeroplane737);
                    }

                    // create seats for planes
                    var seatsA380 = new Seats()
                    {
                        AeroplaneId = aeroplaneA380.AeroplaneId,
                        SeatCount   = 240,
                        InOneRow    = 6
                    };

                    var seats737 = new Seats()
                    {
                        AeroplaneId = aeroplane737.AeroplaneId,
                        SeatCount   = 320,
                        InOneRow    = 8
                    };

                    if (!await seatService.SeatsExist(aeroplaneA380.AeroplaneId))
                    {
                        await seatService.AddSeats(seatsA380);
                    }

                    if (!await seatService.SeatsExist(aeroplane737.AeroplaneId))
                    {
                        await seatService.AddSeats(seats737);
                    }
                }
            }
        }