Exemplo n.º 1
0
        public void UpdateNotificationChannel(byte?channel)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var account = new Account()
                {
                    Id = _accountId,
                    NotificationsChannel = channel
                };

                dbContext.Accounts.Attach(account);
                dbContext.Entry(account).Property(x => x.NotificationsChannel).IsModified = true;

                //dbContext.Configuration.ValidateOnSaveEnabled = false;
                dbContext.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public ServiceOperationResult DeleteMember(Guid memberId)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                ServiceOperationResult result = new ServiceOperationResult();
                result.IsSuccessfull = true;

                var accountId = Guid.Parse(_httpContextAccessor.HttpContext.User.Identity.Name);

                var member = new AccountFamilyMember()
                {
                    Id        = memberId,
                    AccountId = accountId
                };

                dbContext.Entry(member).State = EntityState.Deleted;
                dbContext.SaveChanges();

                return(result);
            }
        }
Exemplo n.º 3
0
        public ServiceOperationResult UpdateAvailability(Guid aircraftAvailabilityId, Guid aircraftId, int?reroutingRadius,
                                                         List <AircraftAvailabilityLocationDto> departureLocations,
                                                         List <AircraftAvailabilityLocationDto> arrivalLocations, List <AircraftAvailabilityPeriodDto> availabileDates,
                                                         decimal?pricePerHour, decimal?minimumAcceptablePrice, bool sellCharterSeat)
        {
            using (FlyJetsDbContext dbContext = new FlyJetsDbContext(_config))
            {
                var operationResult = new ServiceOperationResult();
                operationResult.IsSuccessfull = true;

                var availability = dbContext.AircraftsAvailability
                                   .FirstOrDefault(av => av.Id == aircraftAvailabilityId);

                if (availability == null)
                {
                    operationResult.Errors = new List <ErrorCodes>()
                    {
                        ErrorCodes.NotFound
                    };
                    operationResult.IsSuccessfull = false;

                    return(operationResult);
                }

                availability.AircraftId   = aircraftId;
                availability.PricePerHour = pricePerHour;
                availability.MinimumAcceptablePricePerTrip = minimumAcceptablePrice;
                availability.SellCharterSeat = sellCharterSeat;
                availability.ReroutingRadius = reroutingRadius;

                var oldLocations = dbContext.AircraftAvailabilityLocations
                                   .Where(loc => loc.AircraftAvailabilityId == aircraftAvailabilityId)
                                   .ToList();

                foreach (var location in oldLocations)
                {
                    dbContext.Entry(location).State = EntityState.Deleted;
                }

                availability.Locations = new List <AircraftAvailabilityLocation>();

                if (reroutingRadius.HasValue)
                {
                    var homebaseLoc = (from aircraft in dbContext.Aircrafts
                                       join homebase in dbContext.LocationsTree on aircraft.HomeBaseId equals homebase.Id
                                       where aircraft.Id == aircraftId
                                       select new { Lat = homebase.Lat, Lng = homebase.Lng })
                                      .First();

                    var reroutingLocations = _locationService.GetLocationsWithinXMiles(homebaseLoc.Lat.Value, homebaseLoc.Lng.Value,
                                                                                       reroutingRadius.Value, (byte)LocationsTypes.Airport);

                    foreach (var reroutingLocation in reroutingLocations)
                    {
                        var newLoc = new AircraftAvailabilityLocation()
                        {
                            Id = Guid.NewGuid(),
                            AircraftAvailabilityId = availability.Id,
                            LocationTreeId         = reroutingLocation.Id,
                            IsForDeparture         = true,
                            Rerouting = true
                        };

                        availability.Locations.Add(newLoc);
                    }
                }

                foreach (var departureLocation in departureLocations)
                {
                    var newLoc = new AircraftAvailabilityLocation()
                    {
                        Id = Guid.NewGuid(),
                        AircraftAvailabilityId = availability.Id,
                        LocationTreeId         = departureLocation.LocationTreeId,
                        IsForDeparture         = true,
                        Rerouting = false
                    };

                    availability.Locations.Add(newLoc);
                }

                foreach (var arrivalLocation in arrivalLocations)
                {
                    var newLoc = new AircraftAvailabilityLocation()
                    {
                        Id = Guid.NewGuid(),
                        AircraftAvailabilityId = availability.Id,
                        LocationTreeId         = arrivalLocation.LocationTreeId,
                        IsForDeparture         = false,
                        Rerouting = false
                    };

                    availability.Locations.Add(newLoc);
                }

                var oldPeriods = dbContext.AircraftsAvailabilityPeriods
                                 .Where(p => p.AircraftAvailabilityId == aircraftAvailabilityId)
                                 .ToList();

                foreach (var period in oldPeriods)
                {
                    dbContext.Entry(period).State = EntityState.Deleted;
                }

                availability.Periods = new List <AircraftAvailabilityPeriod>();

                foreach (var availableDate in availabileDates)
                {
                    availability.Periods.Add(new AircraftAvailabilityPeriod()
                    {
                        Id = Guid.NewGuid(),
                        AircraftAvailabilityId = availability.Id,
                        From = availableDate.From,
                        To   = availableDate.To
                    });
                }

                dbContext.SaveChanges();

                return(operationResult);
            }
        }