示例#1
0
        public ServiceOperationResult ChangePassword(string oldPassword, string newPassword)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var account = dbContext.Accounts.FirstOrDefault(acc => acc.Id == _accountId);

                if (PasswordHash.ValidatePassword(oldPassword, account.Password))
                {
                    account.Password = PasswordHash.CreateHash(newPassword);
                    dbContext.SaveChanges();

                    return(new ServiceOperationResult()
                    {
                        IsSuccessfull = true
                    });
                }
                else
                {
                    return(new ServiceOperationResult()
                    {
                        IsSuccessfull = false, Errors = new List <ErrorCodes>()
                        {
                            ErrorCodes.InvalidPassword
                        }
                    });
                }
            }
        }
        public ServiceOperationResult Create(int departureId, int arrivalId, DateTime departureDate, DateTime?arrivalDate, byte bookingType, int passengers)
        {
            var result = new ServiceOperationResult();

            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var newSearch = new SearchHistory()
                {
                    Id            = Guid.NewGuid(),
                    FlyerId       = _accountId,
                    DepartureId   = departureId,
                    DepartureDate = departureDate,
                    ArrivalId     = arrivalId,
                    ArrivalDate   = arrivalDate,
                    BookingType   = bookingType,
                    CreatedOn     = DateTime.UtcNow,
                    Passengers    = passengers
                };

                dbContext.SearchHistories.Add(newSearch);
                try {
                    dbContext.SaveChanges();
                    result.IsSuccessfull = true;
                } catch (Exception e)
                {
                    result.IsSuccessfull = false;
                    result.Errors        = new List <ErrorCodes>()
                    {
                        ErrorCodes.UnKnown
                    };
                }
            }
            return(result);
        }
示例#3
0
 public ServiceOperationResult ResetPassword(string email, string password, string token)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         var account = dbContext.Accounts
                       .FirstOrDefault(acc => acc.Email == email);
         if (account.ResetPasswordCode != null && account.ResetPasswordCode.ToString() == token)
         {
             account.Password = PasswordHash.CreateHash(password);
             dbContext.SaveChanges();
             return(new ServiceOperationResult()
             {
                 IsSuccessfull = true
             });
         }
         else
         {
             return(new ServiceOperationResult()
             {
                 IsSuccessfull = false,
                 Errors = new List <ErrorCodes>()
                 {
                     ErrorCodes.UnKnown
                 }
             });
         }
     }
 }
示例#4
0
        public ServiceOperationResult AddMember(string firstName, string lastName, string email, string mobile,
                                                string address)
        {
            ServiceOperationResult result = new ServiceOperationResult();

            result.IsSuccessfull = true;

            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var accountId = Guid.Parse(_httpContextAccessor.HttpContext.User.Identity.Name);

                var member = new AccountFamilyMember()
                {
                    Id        = Guid.NewGuid(),
                    FirstName = firstName,
                    LastName  = lastName,
                    Email     = email,
                    Mobile    = mobile,
                    Address   = address,
                    AccountId = accountId,
                    CreatedOn = DateTime.UtcNow
                };

                dbContext.AccountFamilyMembers.Add(member);
                dbContext.SaveChanges();

                return(result);
            }
        }
示例#5
0
        public ServiceOperationResult VerifyAccount(string token)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var account = dbContext.Accounts
                              .FirstOrDefault(acc => acc.VerificationCode == token);

                //account is present, meaning user has signed up
                if (account != null)
                {
                    account.Status = (byte)AccountStatuses.Active;
                    try {
                        dbContext.SaveChanges();
                    } catch (DbUpdateException e) {
                        throw e;
                    }
                    return(new ServiceOperationResult()
                    {
                        IsSuccessfull = true
                    });
                }
                else
                {
                    return(new ServiceOperationResult()
                    {
                        IsSuccessfull = false,
                        Errors = new List <ErrorCodes>()
                        {
                            ErrorCodes.NotFound
                        }
                    });
                }
            }
        }
示例#6
0
        public List <AccountFamilyMember> GetFamilyMembers()
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var currentUserId = Guid.Parse(_httpContextAccessor.HttpContext.User.Identity.Name);

                var members = (from member in dbContext.AccountFamilyMembers
                               join account in dbContext.Accounts on member.FlyJestMemberId equals account.Id into g
                               from acc in g.DefaultIfEmpty()
                               where member.AccountId == currentUserId
                               select new AccountFamilyMember
                {
                    Id = member.Id,
                    FirstName = member.FlyJestMemberId.HasValue ? acc.FirstName : member.FirstName,
                    LastName = member.FlyJestMemberId.HasValue ? acc.LastName : member.LastName,
                    DateOfBirth = member.FlyJestMemberId.HasValue ? acc.DateOfBirth : member.DateOfBirth,
                    Email = member.FlyJestMemberId.HasValue ? acc.Email : member.Email,
                    Address = member.FlyJestMemberId.HasValue ? acc.Address : member.Address,
                    Mobile = member.FlyJestMemberId.HasValue ? acc.Mobile : member.Mobile,
                    FlyJestMemberId = member.FlyJestMemberId
                })
                              .ToList();

                return(members);
            }
        }
示例#7
0
 public List <LocationTree> GetLocations(string keyword, int?filter, bool hasCoordinate, int top)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.LocationsTree
                .Where(loc => loc.Name.StartsWith(keyword) &&
                       (filter.HasValue == false
                        ||
                        (
                            (filter & loc.Type) == (int)LocationsTypes.Airport
                            ||
                            (filter & loc.Type) == (int)LocationsTypes.Camp
                            ||
                            (filter & loc.Type) == (int)LocationsTypes.City
                            ||
                            (filter & loc.Type) == (int)LocationsTypes.Country
                            ||
                            (filter & loc.Type) == (int)LocationsTypes.Location
                            ||
                            (filter & loc.Type) == (int)LocationsTypes.State
                        )
                       ) &&
                       (hasCoordinate == false || (loc.Lat.HasValue && loc.Lng.HasValue)))
                .OrderBy(loc => loc.Name)
                .Take(top)
                .ToList());
     }
 }
示例#8
0
        public List <Aircraft> SetAircraftUnavailable(Guid aircraftId)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var aircraft = dbContext.Aircrafts
                               .FirstOrDefault(a => a.Id == aircraftId);

                var availabilities = dbContext.AircraftsAvailability
                                     .Where(av => av.AircraftId == aircraftId);

                var emptyLegs = dbContext.EmptyLegs
                                .Where(el => el.AircraftId == aircraftId);

                foreach (var availability in availabilities)
                {
                    availability.Available = false;
                }

                foreach (var leg in emptyLegs)
                {
                    leg.Available = false;
                }

                dbContext.Aircrafts.Attach(aircraft);

                aircraft.Available = false;

                dbContext.SaveChanges();

                return(GetProviderAircrafts());
            }
        }
示例#9
0
        public Account GetAccount(string email)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var account = dbContext.Accounts.FirstOrDefault(acc => acc.Email == email);

                return(account);
            }
        }
示例#10
0
 internal List <TaxType> GetTaxesTypes()
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.TaxesTypes
                .OrderBy(ft => ft.Order)
                .ToList());
     }
 }
示例#11
0
 public List <LocationTree> GetLocationsTree(string keyword, int top)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.LocationsTree
                .Where(loc => loc.Name.StartsWith(keyword))
                .OrderBy(loc => loc.Name)
                .ToList());
     }
 }
示例#12
0
 public byte?GetNotificationChannels()
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return((from account in dbContext.Accounts
                 where account.Id == _accountId
                 select account.NotificationsChannel)
                .FirstOrDefault());
     }
 }
示例#13
0
 public AccountPaymentMethod GetPaymentMethod(Guid paymentMethodId)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return((from pm in dbContext.AccountPaymentMethods
                 where pm.AccountId == _accountId && pm.Id == paymentMethodId
                 select pm)
                .FirstOrDefault());
     }
 }
示例#14
0
 public List <AccountPaymentMethod> GetPaymentMethods(byte usedFor)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return((from pm in dbContext.AccountPaymentMethods
                 where pm.AccountId == _accountId && pm.UsedFor == usedFor
                 select pm)
                .ToList());
     }
 }
示例#15
0
 public List <Account> GetFlyers()
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.Accounts
                .Where(acc => acc.Type == (byte)AccountTypes.Flyer)
                .OrderByDescending(acc => acc.CreatedOn)
                .ToList());
     }
 }
示例#16
0
        public LocationTree GetLocation(int id)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var location = dbContext.LocationsTree
                               .Include("City")
                               .FirstOrDefault(loc => loc.Id == id);

                return(location);
            }
        }
示例#17
0
 public List <AircraftAvailability> GetAvailability()
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.AircraftsAvailability
                .Include("Aircraft.Model")
                .Include("Aircraft.Type")
                .Where(av => av.Aircraft.ProviderId == _accountId && av.Available == true)
                .ToList());
     }
 }
示例#18
0
 public List <Aircraft> Search(Guid aircraftProviderId, string tailNumber)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return((from aircraft in dbContext.Aircrafts
                 where aircraft.ProviderId == aircraftProviderId &&
                 aircraft.TailNumber.StartsWith(tailNumber)
                 select aircraft)
                .ToList());
     }
 }
示例#19
0
 public EmptyLeg GetEmptyLeg(Guid emptyLegId)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.EmptyLegs
                .Include(leg => leg.Aircraft)
                .Include(leg => leg.DepartureAirport)
                .Include(leg => leg.ArrivalAirport)
                .FirstOrDefault(leg => leg.Id == emptyLegId));
     };
 }
示例#20
0
 public List <Account> Search(byte type, string keyword)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.Accounts
                .Where(acc => acc.Type == type &&
                       (acc.FirstName.StartsWith(keyword) ||
                        acc.LastName.StartsWith(keyword)))
                .ToList());
     }
 }
示例#21
0
 public List <Account> GetAircraftProviders(bool filterByPending)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.Accounts
                .Where(acc => acc.Type == (byte)AccountTypes.AircraftProvider &&
                       (filterByPending == false || acc.Status == (byte)AccountStatuses.PendingApproval))
                .OrderByDescending(acc => acc.CreatedOn)
                .ToList());
     }
 }
示例#22
0
 public List <EmptyLeg> GetList()
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.EmptyLegs
                .Include(leg => leg.Aircraft)
                .Include(leg => leg.DepartureAirport)
                .Include(leg => leg.ArrivalAirport)
                .Where(el => el.Aircraft.ProviderId == _accountId && el.Available == true)
                .OrderByDescending(el => el.CreatedOn)
                .ToList());
     };
 }
        public void NewCreate(Guid receiverId, NotificationsTypes type, string text, List <NotificationParam> @params)
        {
            var newNotification = PrepareNotification(receiverId, type, text, @params);

            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                //send notification to database
                dbContext.Notifications.Add(newNotification);

                dbContext.SaveChanges();
            }
            //get list of unread notifications
            /* GetNotifications(receiverId); */
        }
示例#24
0
        //public List<AircraftAvailabilityResultDto> SearchAvailability2(int departureId, int arrivalId, DateTime departureDate,
        //    DateTime? returnDate, short pax, byte bookingType, byte direction)
        //{
        //    using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
        //    {
        //        var departure = _locationService.GetLocation(departureId);
        //        var arrival = _locationService.GetLocation(arrivalId);

        //        var distance = Utilities.GetDistance(departure.Lat.Value, departure.Lng.Value, arrival.Lat.Value, arrival.Lng.Value) / 1852;

        //        var aircrafts = (from aircraft in dbContext.Aircrafts
        //                         join model in dbContext.AircraftModels on aircraft.ModelId equals model.Id
        //                         join type in dbContext.AircraftTypes on aircraft.TypeId equals type.Id
        //                         join homebase in dbContext.LocationsTree on aircraft.HomeBaseId equals homebase.Id
        //                         join availability in dbContext.AircraftsAvailability on aircraft.Id equals availability.AircraftId
        //                         where dbContext.AircraftAvailabilityLocations
        //                                    .Any(aal => aal.AircraftAvailabilityId == availability.Id
        //                                            && aal.IsForDeparture == true
        //                                            && (
        //                                                aal.Location.LocationId == departure.LocationId
        //                                                ||
        //                                                (aal.Location.LocationId == null && aal.Location.CityId == departure.CityId)
        //                                                ||
        //                                                (aal.Location.LocationId == null && aal.Location.CityId == null && aal.Location.StateId.HasValue && aal.Location.StateId == departure.StateId)
        //                                                ||
        //                                                (aal.Location.LocationId == null && aal.Location.CityId == null && aal.Location.StateId == null && aal.Location.CountryId == departure.CountryId)
        //                                                ))
        //                                &&
        //                                    dbContext.AircraftAvailabilityLocations
        //                                    .Any(aal => aal.AircraftAvailabilityId == availability.Id
        //                                            && aal.IsForDeparture == false
        //                                            && (
        //                                                aal.Location.LocationId == arrival.LocationId
        //                                                ||
        //                                                (aal.Location.LocationId == null && aal.Location.CityId == arrival.CityId)
        //                                                ||
        //                                                (aal.Location.LocationId == null && aal.Location.CityId == null && aal.Location.StateId.HasValue && aal.Location.StateId == arrival.StateId)
        //                                                ||
        //                                                (aal.Location.LocationId == null && aal.Location.CityId == null && aal.Location.StateId == null && aal.Location.CountryId == arrival.CountryId)
        //                                                ))
        //                             &&
        //                                dbContext.AircraftsAvailabilityPeriods
        //                                .Any(aap => aap.AircraftAvailabilityId == availability.Id
        //                                            && aap.From <= departureDate && aap.To >= departureDate)
        //                             &&
        //                                (returnDate.HasValue == false
        //                                ||
        //                                dbContext.AircraftsAvailabilityPeriods
        //                                .Any(aap => aap.AircraftAvailabilityId == availability.Id
        //                                            && aap.From <= departureDate && aap.To >= departureDate))
        //                             && ((bookingType == (byte)BookingTypes.CharterAircraft)
        //                                 ||
        //                                 (bookingType == (byte)BookingTypes.CharterSeat && availability.SellCharterSeat == true))
        //                         select new
        //                         {
        //                             AircraftAvailabilityId = availability.Id,
        //                             AircraftId = aircraft.Id,
        //                             Departure = departure.DisplayName,
        //                             Arrival = arrival.DisplayName,
        //                             AircraftModel = model.Name,
        //                             AircraftPax = aircraft.MaxPassengers,
        //                             AircraftType = type.Name,
        //                             AircraftArgusSafetyRating = aircraft.ArgusSafetyRating,
        //                             AircraftSpeed = aircraft.Speed,
        //                             AircraftRange = aircraft.Range,
        //                             PricePerHour = availability.PricePerHour,
        //                             MinimumAcceptablePricePerTrip = availability.MinimumAcceptablePricePerTrip,
        //                             HomeBaseId = aircraft.HomeBaseId,
        //                             HomeBaseLat = homebase.Lat,
        //                             HomeBaseLng = homebase.Lng,
        //                             WiFi = aircraft.WiFi,
        //                             NumberOfTelevision = aircraft.NumberOfTelevision
        //                         })
        //                .ToList();


        //        List<AircraftAvailabilityResultDto> finalAircrafts = new List<AircraftAvailabilityResultDto>();

        //        var aircraftsIds = aircrafts.Select(a => a.AircraftId).ToList();
        //        var aircraftsDefaultImages = (from image in dbContext.AircraftImages
        //                                      where image.Order == 1
        //                                            && aircraftsIds.Any(id => id == image.AircraftId)
        //                                      select new { AircraftId = image.AircraftId, FileName = image.FileName })
        //                                      .ToList();

        //        foreach (var aircraft in aircrafts)
        //        {
        //            if (departureId != aircraft.HomeBaseId)
        //            {
        //                var homebaseGC = new { aircraft.HomeBaseLat, aircraft.HomeBaseLng };

        //                var reroutingDestance = Utilities.GetDistance(homebaseGC.HomeBaseLat.Value, homebaseGC.HomeBaseLng.Value, departure.Lat.Value, departure.Lng.Value) / 1852;

        //                distance += reroutingDestance;
        //            }

        //            var duration = _flightService.CalculateFlightDuration(distance, aircraft.AircraftSpeed);

        //            var bookingCost = _bookingService.CalculateCost(bookingType, direction, duration,
        //                aircraft.PricePerHour, aircraft.MinimumAcceptablePricePerTrip, aircraft.AircraftPax);

        //            var defaultImage = aircraftsDefaultImages.FirstOrDefault(img => img.AircraftId == aircraft.AircraftId);

        //            AircraftAvailabilityResultDto finalAircraft = new AircraftAvailabilityResultDto()
        //            {
        //                AircraftAvailabilityId = aircraft.AircraftAvailabilityId,
        //                AircraftId = aircraft.AircraftId,
        //                Departure = aircraft.Departure,
        //                Arrival = aircraft.Arrival,
        //                FlightDurationHours = duration.Hours,
        //                FlightDurationMinutes = duration.Minutes,
        //                AircraftModel = aircraft.AircraftModel,
        //                AircraftPax = aircraft.AircraftPax,
        //                AircraftType = aircraft.AircraftType,
        //                AircraftArgusSafetyRating = aircraft.AircraftArgusSafetyRating,
        //                AircraftSpeed = aircraft.AircraftSpeed,
        //                AircraftRange = aircraft.AircraftRange,
        //                DefaultImageUrl = defaultImage == null ? "" : _config["AircraftImagesUrl"] + defaultImage.FileName,
        //                WiFi = aircraft.WiFi,
        //                NumberOfTelevision = aircraft.NumberOfTelevision
        //            };

        //            finalAircraft.TotalPrice = bookingCost.TotalCost;
        //            finalAircraft.ExclusiveTotalPrice = bookingCost.TotalExclusiveCost;
        //            finalAircraft.TotalFees = bookingCost.TotalFeesCost;
        //            finalAircraft.TotalTaxes = bookingCost.TotalTaxesCost;

        //            finalAircrafts.Add(finalAircraft);
        //        }

        //        return finalAircrafts;
        //    }
        //}

        public Aircraft Get(Guid aircraftId)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var aircraft = dbContext.Aircrafts
                               .Include(a => a.Model)
                               .Include(a => a.Type)
                               .Include(a => a.HomeBase)
                               .Include(a => a.Images)
                               .FirstOrDefault(a => a.Id == aircraftId);

                return(aircraft);
            }
        }
        public List <SearchHistory> GetSearchHistories()
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var histories = dbContext.SearchHistories
                                .Include("Flyer")
                                .Include("Departure")
                                .Include("Arrival")
                                .OrderByDescending(h => h.CreatedOn)
                                .ToList();

                return(histories);
            }
        }
示例#26
0
        public Account GetAccount(Guid?id = null)
        {
            if (id.HasValue == false)
            {
                id = Guid.Parse(_httpContextAccessor.HttpContext.User.Identity.Name);
            }

            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var account = dbContext.Accounts
                              .FirstOrDefault(acc => acc.Id == id);

                return(account);
            }
        }
示例#27
0
        public AircraftAvailability GetAvailability(Guid aircraftAvailabilityId)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var availability = dbContext.AircraftsAvailability
                                   .Include("Aircraft.Model")
                                   .Include("Locations.Location.City")
                                   .Include("Locations.Location.State")
                                   .Include("Locations.Location.Country")
                                   .Include("Periods")
                                   .FirstOrDefault(av => av.Id == aircraftAvailabilityId);

                return(availability);
            }
        }
示例#28
0
 public Flight GetCharterSeatFlight(Guid aircraftId, int departureId, int arrivalId, DateTime departureDate)
 {
     using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
     {
         return(dbContext.Flights
                .Where(flight => (flight.FlightType == (byte)BookingTypes.CharterAircraftSeat || flight.FlightType == (byte)BookingTypes.CharterFlightSeat) &&
                       flight.AircraftId == aircraftId &&
                       flight.DepartureId == departureId &&
                       flight.ArrivalId == arrivalId &&
                       flight.DepartureDate.Year == departureDate.Year &&
                       flight.DepartureDate.Month == departureDate.Month &&
                       flight.DepartureDate.Day == departureDate.Day)
                .FirstOrDefault());
     }
 }
示例#29
0
        public List <Aircraft> GetProviderAircrafts()
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var aircrafts = dbContext.Aircrafts
                                .Include(a => a.Model)
                                .Include(a => a.Type)
                                .Include(a => a.HomeBase)
                                .Include(a => a.Images)
                                .Where(a => a.ProviderId == _accountId && a.Available == true)
                                .OrderByDescending(a => a.CreatedOn)
                                .ToList();

                return(aircrafts);
            }
        }
示例#30
0
        public List <EmptyLeg> SetLegUnavailable(Guid emptyLegId)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var emptyLeg = dbContext.EmptyLegs
                               .FirstOrDefault(leg => leg.Id == emptyLegId);

                dbContext.EmptyLegs.Attach(emptyLeg);

                emptyLeg.Available = false;

                dbContext.SaveChanges();

                return(GetList());
            }
        }