public static async Task<RoomsChoiceViewModel> CreateAsync(DateRange dates) { RoomsChoiceViewModel newInstance = new RoomsChoiceViewModel(); newInstance._availableRooms = await RoomRepository.GetAvailablesBetweenAsync(dates); int i = 0; foreach (Room room in newInstance._availableRooms) { if (!newInstance._availableRoomCounts.ContainsKey(room.Kind)) { newInstance._availableRoomCounts.Add(room.Kind, 1); RoomChoiceEntity roomChoice = new RoomChoiceEntity(room.Kind, 0, 0); newInstance._availableRoomChoiceEntities.Add(roomChoice); i++; } else { newInstance._availableRoomCounts[room.Kind]++; } } foreach (RoomChoiceEntity roomChoice in newInstance._availableRoomChoiceEntities) { roomChoice.MaxAvailable = newInstance._availableRoomCounts[roomChoice.RoomKind]; } return newInstance; }
public object Clone() { DateRange dateRange = new DateRange { Start = new DateTime(Start.Ticks), End = new DateTime(End.Ticks) }; return dateRange; }
/// <summary> /// Gets Available Options within requested DateRange. /// </summary> /// <param name="dateRange"></param> /// <returns></returns> public static async Task<List<Option>> GetAvailablesBetweenAsync(DateRange dateRange) { using (ResotelContext ctx = new ResotelContext()) { List<Option> availableOptions = await ctx.Options .Include( opt => opt.Discounts.Select( discount => discount.Validity ) ) .Where(Option.IsAvailableBetween(dateRange)) .ToListAsync(); return availableOptions; } }
/// <summary> /// Gets all available Rooms wihin requested dateRange /// A Room is available for a given dateRange if it has no booking including those dates save the last which may be on a booking's startDate /// </summary> /// <param name="dateRange"></param> /// <returns></returns> public static async Task<List<Room>> GetAvailablesBetweenAsync(DateRange dateRange) { using (ResotelContext ctx = new ResotelContext()) { List<Room> availableRooms = await ctx.Rooms .Include(room => room.Options.Select(opt => opt.Discounts.Select(discount => discount.Validity))) .Include( room => room.AvailablePacks ) .Where(Room.NotBookedDuring(dateRange)) .ToListAsync(); return availableRooms; } }
/// <summary> /// Charge une liste d'options à partir d'options existantes d'une réservation. /// </summary> /// <param name="booking">réservation existante pour mémoire</param> /// <param name="dates">plage de date de la réservation</param> /// <returns></returns> public static async Task<OptionsViewModel> CreateAsync(Booking booking, DateRange dates) { OptionsViewModel newInstance = new OptionsViewModel(); List<Option> availableOptions = await OptionRepository.GetAvailablesBetweenAsync(dates); _setAvailableOptionChoiceEntities(booking, dates, newInstance, availableOptions); foreach (OptionChoiceEntity optChoiceEntity in newInstance._availableOptionChoiceEntities) { optChoiceEntity.PropertyChanged += newInstance._optionChanged; } return newInstance; }
/// <summary> /// Gets all Room with given Options available within requested dateRange /// </summary> /// <param name="options"></param> /// <param name="dateRange"></param> /// <returns></returns> public static async Task<List<Room>> GetMatchingRoomsBetween(IEnumerable<Option> options, DateRange dateRange) { using (ResotelContext ctx = new ResotelContext()) { List<Room> matchingRooms = await ctx.Rooms .Include( room => room.Options.Select( opt => opt.Discounts.Select( discount => discount.Validity ) ) ) .Include( room => room.AvailablePacks) .Where( Room.NotBookedDuring(dateRange) .And(Room.WithOptions(options)) ) .ToListAsync(); return matchingRooms; } }
public Booking() { Client = new Client(); OptionChoices = new List<OptionChoice>(); Rooms = new List<Room>(); Dates = new DateRange(); _roomDiscounts = new List<AppliedDiscount>(); _propertiesValidations = new Dictionary<string, Func<string>> { { nameof(Client), _validateClient }, { nameof(OptionChoices), _validateOptions }, { nameof(Rooms), _validateRooms }, { nameof(Dates), _validateDates }, { nameof(AdultsCount), _validateAdultsCount }, { nameof(BabiesCount), _validateBabiesCount } }; }
public SumUpViewModel(LinkedList<INavigableViewModel> navigation, Booking booking, LinkedListNode<INavigableViewModel> prevNode = null) { _pcs = new PropertyChangeSupport(this); _navigation = navigation; _booking = booking; _dates = booking.Dates; _clientEntity = new ClientEntity(booking.Client); _paymentEntity = new PaymentEntity(booking); _paymentEntity.PropertyChanged += _payment_changed; _hasPayment = _booking.Payment != null && _booking.Payment.Ammount > 0d; _hadPayment = _hasPayment; _wasInTempState = _booking.State == BookingState.Validated; _appliedPackEntities = new List<AppliedPackEntity>(); _optionChoiceEntities = new List<OptionChoiceEntity>(booking.OptionChoices.Count); _updateOptionChoiceEntities(booking); _title = $"Réservation de {_clientEntity.FirstName} {_clientEntity.LastName} du {booking.Dates.Start:dd/MM/yyyy}"; _fillAppliedPacksEntities(booking); bool canSave = _booking.State == BookingState.Validated; _defineCommands(canSave); _definePaymentModes(); _unlockSaveIfNeeded(); _unlockEditIfNeeded(); if ((_booking.State != BookingState.Validated && canSave) || (_booking.State == BookingState.Validated && !canSave) ) { _saveBookingCommand.ChangeCanExecute(); } if (prevNode != null) { _navigation.AddAfter(prevNode, this); } else { _navigation.AddLast(this); } }
private static Expression<Func<Option, bool>> _noBookedRoomDuring(DateRange dateRange) { return opt => opt.Rooms.AsQueryable().Any(Room.NotBookedDuring(dateRange)); }
/// <summary> /// Indicated wether some rooms are left with this Option, for the requested date /// </summary> /// <param name="dateRange">requested date</param> /// <returns>true if some available rooms with this one are found</returns> public static Expression<Func<Option, bool>> IsAvailableBetween(DateRange dateRange) { Expression<Func<Option, bool>> noRooms = opt => opt.Rooms.Count == 0; return noRooms .Or(_noBookedRoomDuring(dateRange)); }
private static void _updateTrackedOptionDates(DateRange trackedOptDates, DateRange newDateRange, ResotelContext ctx) { ctx.Entry(trackedOptDates).CurrentValues.SetValues(newDateRange); }
private static void _setAvailableOptionChoiceEntities(Booking booking, DateRange dates, OptionsViewModel newInstance, List<Option> availableOptions) { foreach (Option opt in availableOptions) { OptionChoice optChoice = new OptionChoice { Option = opt, TakenDates = (DateRange)((ICloneable)dates).Clone() }; optChoice.TakenDates.Start = optChoice.TakenDates.Start.Date; if (optChoice.Option.Id == 8) { optChoice.TakenDates.Start = optChoice.TakenDates.Start.AddDays(1.0d); } OptionChoiceEntity optChoiceEntity = new OptionChoiceEntity(booking, optChoice); newInstance._availableOptionChoiceEntities.Add(optChoiceEntity); } }
public static Expression <Func <Room, bool> > NotBookedDuring(DateRange dateRange) { return(_hasNoBooking() .Or(_bookingsStartedAfter(dateRange.End)) .Or(_bookingsEndedBefore(dateRange.Start))); }
private static Expression <Func <Option, bool> > _noBookedRoomDuring(DateRange dateRange) { return(opt => opt.Rooms.AsQueryable().Any(Room.NotBookedDuring(dateRange))); }
public DateRangeEntity(DateRange dateRange) { _pcs = new PropertyChangeSupport(this); _dateRange = dateRange; }
private async Task _saveBooking(SumUpViewModel sumUpVM) { try { bool isNew = _booking.Id == 0; Logger.Log($"Enregistrement de la {(isNew ? "nouvelle " : "")}réservation: {(isNew ? "" : _booking.Id.ToString())}"); bool paymentSet = false; if (_hasPayment && !_hadPayment) { sumUpVM._booking.Payment.Date = DateTime.Now; paymentSet = true; } await BookingRepository.Save(sumUpVM._booking); Logger.Log("Enregistrement de réservation : réussi"); _unlockEditIfNeeded(); if (paymentSet) { _saveBookingCommand.ChangeCanExecute(); } DateRange todayRange = new DateRange { Start = DateTime.Now.Date, End = DateTime.Now.Date.AddDays(1.0d) }; Logger.Log("Enregistrement de réservation : Récupération des chambres disponibles"); List<Room> availableRoomsToday = await RoomRepository.GetAvailablesBetweenAsync(todayRange); if(availableRoomsToday.Count < 5) { Logger.Log("Enregistrement de réservation : Alerte -5 chambres disponibles"); await Mailer.SendAsync("Il y a moins de 5 chambres disponibles"); } PromptViewModel successPromptVM = new PromptViewModel("Succés", "La commande a réussi", false); ViewDriverProvider.ViewDriver.ShowView<PromptViewModel>(successPromptVM); } catch(Exception ex) { Logger.Log(ex); } }
private async Task _validateParameters() { try { _parametersValidated = true; bool newClientCanExecute = _newClientCommand.CanExecute(null); bool searchClientCanExecute = _searchClientCommand.CanExecute(null); bool validateBookingCanExecute = _validateBookingCommand.CanExecute(null); _handleCommandStates(newClientCanExecute, searchClientCanExecute, validateBookingCanExecute); DateRange dateRange = new DateRange { Start = _parameters.Start, End = _parameters.End }; Options = await OptionsViewModel.CreateAsync(_booking, dateRange); RoomChoices = await RoomsChoiceViewModel.CreateAsync(dateRange); RoomChoices.AvailableRoomChoiceEntitiesView.Filter = _mustShowRoomChoice; _updateOptionChoicesEntities(); Dictionary<RoomKind, int> takenRoomKind = new Dictionary<RoomKind, int>(); _countTakenRooms(takenRoomKind); _setRoomChoiceEntitiesCounts(takenRoomKind); } catch (Exception ex) { Logger.Log(ex); } }
private async void _parameters_defined(object sender, BookingParametersViewModel bookingParametersVM) { try { ParametersValidated = true; DateRange dateRange = new DateRange { Start = _parameters.Start, End = _parameters.End }; Options = await OptionsViewModel.CreateAsync(_booking, dateRange); RoomChoices = await RoomsChoiceViewModel.CreateAsync(dateRange); RoomChoices.AvailableRoomChoiceEntitiesView.Filter = _mustShowRoomChoice; _newClientCommand.ChangeCanExecute(); _searchClientCommand.ChangeCanExecute(); _validateBookingCommand.ChangeCanExecute(); } catch (Exception ex) { Logger.Log(ex); } }
public static Expression<Func<Room, bool>> NotBookedDuring(DateRange dateRange) { return _hasNoBooking() .Or(_bookingsStartedAfter(dateRange.End)) .Or(_bookingsEndedBefore(dateRange.Start)); }
private static async Task<DateRange> _getTrackedBookingDates(DateRange newBookingDates, ResotelContext ctx) { DateRange trackedBookingDates = await ctx.Set<DateRange>().FirstOrDefaultAsync(dr => dr.Id == newBookingDates.Id); if (trackedBookingDates == null) { trackedBookingDates = ctx.Set<DateRange>().Attach(newBookingDates); } else { // check ctx.Entry(trackedBookingDates).CurrentValues.SetValues(newBookingDates); } return trackedBookingDates; }