public async Task <JsonResult> Get([FromQuery] DateTime start, [FromQuery] DateTime end) { var bookings = await BookingService.FindBookingsInInterval(new SearchBookingSummariesQuery { Start = start, End = end, IsCancelled = false }); var expandedBookingDays = bookings.SelectMany(b => b.ExpandDays()); IExecutionContext executionContext = await ExecutionContextFactory.CreateAsync(); bool hasEditAccess = PermissionValidationService.HasCustomEntityPermission <CustomEntityUpdatePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); var events = expandedBookingDays.Select(b => new CalendarEvent { start = b.Date, title = "Optaget", description = hasEditAccess ? $"#{b.Booking.BookingNumber} - {b.Booking.Purpose}" : null, booking_id = hasEditAccess ? b.Booking.Id : (int?)null }); return(new JsonResult(events)); }
public async Task ExecuteAsync(DeleteAllBookingsCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityDeletePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); foreach (var booking in (await BookingProvider.FindBookingsInInterval(new SearchBookingSummariesQuery())).ToList()) { var deleteCmd = new DeleteBookingCommand { Id = booking.Id }; await CommandExecutor.ExecuteAsync(deleteCmd); } }
public async Task ExecuteAsync(SendStatusMailCommand command, IExecutionContext executionContext) { DateTime startDate = DateTime.Now.AddDays(-14); DateTime endDate = DateTime.Now.AddDays(14); string calendarContent = await StatusMailProvider.BuildStatusCalendar(startDate, endDate); SearchBookingSummariesQuery query = new SearchBookingSummariesQuery { Start = new DateTime(DateTime.Now.Year, 1, 1), End = new DateTime(DateTime.Now.Year, 12, 31), //BookingState = new BookingDataModel.BookingStateType[] { BookingDataModel.BookingStateType.Requested, BookingDataModel.BookingStateType.Approved } }; var bookings = (await BookingProvider.FindBookingsInInterval(query)).Where(b => !b.IsCancelled).ToList(); int bookingCount = bookings.Count; decimal bookingTotalIncome = bookings.Sum(b => b.RentalPrice ?? 0.0M); TemplateDataModel template = await TemplateProvider.GetTemplateByName("statusmail"); Dictionary <string, object> mergeData = new Dictionary <string, object> { ["date"] = DateTime.Now.Date, ["bookingCount"] = bookingCount, ["bookingTotalIncome"] = bookingTotalIncome, ["calendar"] = calendarContent }; string mailContent = TemplateProvider.MergeText(template.Text, mergeData); MailAddress to = new MailAddress(Settings.MailReceiver); MailMessage message = new MailMessage { To = to, Subject = "Bøgevang statusopdatering", HtmlBody = mailContent }; await MailDispatchService.DispatchAsync(message); }
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()})."); } }
public async Task <IList <BookingSummary> > ExecuteAsync(SearchBookingSummariesQuery query, IExecutionContext executionContext) { return(await BookingProvider.FindBookingsInInterval(query)); }