public async Task ExecuteAsync(BookingRequestCommand command, IExecutionContext executionContext) { using (var scope = DomainRepository.Transactions().CreateScope()) { var tenantCategory = await TenantCategoryProvider.GetTenantCategoryById(command.TenantCategoryId.Value); DateTime lastAllowedArrivalDate = DateTime.Now.AddMonths(tenantCategory.AllowedBookingFutureMonths); if (command.ArrivalDate.Value >= lastAllowedArrivalDate || command.DepartureDate.Value >= lastAllowedArrivalDate) { throw new ValidationErrorException(new ValidationError($"Den valgte lejertype kan ikke reservere mere end {tenantCategory.AllowedBookingFutureMonths} måneder ud i fremtiden. Dvs. senest {lastAllowedArrivalDate.ToShortDateString()}.", nameof(command.ArrivalDate))); } int bookingNumber = await SequenceNumberGenerator.NextNumber("BookingNumber"); var booking = new BookingDataModel { BookingNumber = bookingNumber, ArrivalDate = command.ArrivalDate.Value, DepartureDate = command.DepartureDate.Value, OnlySelectedWeekdays = command.OnlySelectedWeekdays, SelectedWeekdays = command.SelectedWeekdays, TenantCategoryId = command.TenantCategoryId.Value, TenantName = command.TenantName, Purpose = command.Purpose, ContactName = command.ContactName, ContactPhone = command.ContactPhone, ContactAddress = command.ContactAddress, ContactCity = command.ContactCity, ContactEMail = command.ContactEMail, Comments = command.Comments, RentalPrice = null, // To be set later Deposit = BookingSettings.StandardDeposit, BookingState = BookingDataModel.BookingStateType.Requested }; await booking.AddLogEntry(CurrentUserProvider, "Reservationen blev indsendt af lejer."); await SendConfirmationMail(booking); await SendNotificationMail(booking); var addCommand = new AddCustomEntityCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, Model = booking, Title = booking.MakeTitle(), Publish = true, }; await DomainRepository.WithElevatedPermissions().CustomEntities().AddAsync(addCommand); await scope.CompleteAsync(); } }
public async Task ExecuteAsync(UpdateBookingCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); using (var scope = DomainRepository.Transactions().CreateScope()) { // Verify teneant category await TenantCategoryProvider.GetTenantCategoryById(command.TenantCategoryId.Value); BookingDataModel booking = await BookingProvider.GetBookingById(command.BookingId); booking.ArrivalDate = command.ArrivalDate.Value; booking.DepartureDate = command.DepartureDate.Value; booking.OnlySelectedWeekdays = command.OnlySelectedWeekdays; booking.SelectedWeekdays = command.SelectedWeekdays; booking.TenantCategoryId = command.TenantCategoryId; booking.TenantName = command.TenantName; booking.Purpose = command.Purpose; booking.ContactName = command.ContactName; booking.ContactPhone = command.ContactPhone; booking.ContactAddress = command.ContactAddress; booking.ContactCity = command.ContactCity; booking.ContactEMail = command.ContactEMail; booking.Comments = command.Comments; booking.RentalPrice = command.RentalPrice; booking.BookingState = command.BookingState; booking.IsApproved = command.IsApproved; booking.IsCancelled = command.IsCancelled; booking.IsCheckedOut = command.IsCheckedOut; booking.IsArchived = command.IsArchived; booking.WelcomeLetterIsSent = command.WelcomeLetterIsSent; booking.Deposit = command.Deposit; booking.DepositReceived = command.DepositReceived; booking.ElectricityReadingStart = command.ElectricityReadingStart; booking.ElectricityReadingEnd = command.ElectricityReadingEnd; booking.ElectricityPriceUnit = command.ElectricityPriceUnit; UpdateCustomEntityDraftVersionCommand updateCmd = new UpdateCustomEntityDraftVersionCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, CustomEntityId = command.BookingId, Title = booking.MakeTitle(), Publish = true, Model = booking }; await DomainRepository.CustomEntities().Versions().UpdateDraftAsync(updateCmd); await scope.CompleteAsync(); } }
public async Task UpdateCalculatedValues( IBookingProvider bookingProvider, ITenantCategoryProvider tenantCategoryProvider, BookingSettings settings) { Alert = null; if (IsCancelled) { Alert = AlertType.Cancelled; AlertMessage = "Aflyst."; BookingStateText = "Aflyst"; } else if (BookingState == BookingDataModel.BookingStateType.Requested) { Alert = AlertType.New; AlertMessage = "Ny reservation."; } else if (BookingState == BookingDataModel.BookingStateType.Approved) { if (!WelcomeLetterIsSent && DateTime.Now > ArrivalDate - TimeSpan.FromDays(settings.DaysBeforeArrivalForWelcomeLetter)) { Alert = AlertType.Key; AlertMessage = "Velkomstbrev skal udsendes."; } else if (DateTime.Now > DepartureDate) { if (!IsCheckedOut) { Alert = AlertType.AwaitingCheckout; AlertMessage = "Afventer slutafregning fra lejer."; } else { Alert = AlertType.Finalize; AlertMessage = "Lejemålet er overstået og skal afsluttes."; } } } Notifications = new List <Notification>(); var tenantCategory = await tenantCategoryProvider.GetTenantCategoryById(TenantCategoryId); DateTime lastAllowedArrivalDate = CreatedDate.AddMonths(tenantCategory.AllowedBookingFutureMonths); if (ArrivalDate >= lastAllowedArrivalDate) { AddNotification(NotificationLevelType.Warning, $"Bemærk at ankomstdatoen ligger mere end de tilladte {tenantCategory.AllowedBookingFutureMonths} måneder efter at ansøgningen blev oprettet. " + $"Datoen er beregnet på baggrund af lejerkategorien."); } if (RentalPrice == null) { AddNotification(NotificationLevelType.Warning, "Bemærk at der endnu ikke er aftalt nogen pris."); } // Look up overlap for active bookings (no need to add warning for historic bookings) if (BookingState != BookingDataModel.BookingStateType.Closed) { var overlappingBookings = await bookingProvider.FindBookingsInInterval(new Queries.SearchBookingSummariesQuery { Start = ArrivalDate, End = DepartureDate, IsCancelled = false }); foreach (var booking in overlappingBookings) { // Do not include self if (booking.Id != Id && booking.CollidesWith(this)) { AddNotification(NotificationLevelType.Warning, $"Denne reservation overlapper med reservation nr. {booking.BookingNumber} den {booking.ArrivalDate.ToShortDateString()} til {booking.DepartureDate.ToShortDateString()}."); } } } if (BookingState == BookingDataModel.BookingStateType.Closed) { AddNotification(NotificationLevelType.Information, $"Denne reservation er afsluttet ({GetSingleWordStateDescription()})."); } }