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); }
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 } }); } } }
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); } }
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 } }); } } }
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); } }
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()); } }
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()); } }
public Account GetAccount(string email) { using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config)) { var account = dbContext.Accounts.FirstOrDefault(acc => acc.Email == email); return(account); } }
internal List <TaxType> GetTaxesTypes() { using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config)) { return(dbContext.TaxesTypes .OrderBy(ft => ft.Order) .ToList()); } }
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()); } }
public byte?GetNotificationChannels() { using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config)) { return((from account in dbContext.Accounts where account.Id == _accountId select account.NotificationsChannel) .FirstOrDefault()); } }
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()); } }
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()); } }
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()); } }
public LocationTree GetLocation(int id) { using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config)) { var location = dbContext.LocationsTree .Include("City") .FirstOrDefault(loc => loc.Id == id); return(location); } }
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()); } }
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()); } }
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)); }; }
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()); } }
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()); } }
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); */ }
//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); } }
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); } }
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); } }
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()); } }
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); } }
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()); } }