public async Task ExecuteAsync(CancelBookingCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); using (var scope = DomainRepository.Transactions().CreateScope()) { var booking = await BookingProvider.GetBookingById(command.Id); booking.BookingState = BookingDataModel.BookingStateType.Closed; booking.IsCancelled = true; var user = await CurrentUserProvider.GetAsync(); booking.AddLogEntry(new BookingLogEntry { Text = "Reservationen blev aflyst.", Username = user.User.GetFullName(), UserId = user.User.UserId, Timestamp = DateTime.Now }); UpdateCustomEntityDraftVersionCommand updateCmd = new UpdateCustomEntityDraftVersionCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, CustomEntityId = command.Id, Title = booking.MakeTitle(), Publish = true, Model = booking }; await DomainRepository.CustomEntities().Versions().UpdateDraftAsync(updateCmd); await scope.CompleteAsync(); } }
public async Task ExecuteAsync(SendWelcomeLetterCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); using (var scope = DomainRepository.Transactions().CreateScope()) { var booking = await BookingProvider.GetBookingById(command.Id); booking.WelcomeLetterIsSent = true; // Welcome is not really sent here, we only redirect to the mail editing-and-sending page afterwards. var user = await CurrentUserProvider.GetAsync(); booking.AddLogEntry(new BookingLogEntry { Text = "Velkomstbrev er udsendt.", Username = user.User.GetFullName(), UserId = user.User.UserId, Timestamp = DateTime.Now }); UpdateCustomEntityDraftVersionCommand updateCmd = new UpdateCustomEntityDraftVersionCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, CustomEntityId = command.Id, Title = booking.MakeTitle(), Publish = true, Model = booking }; await DomainRepository.CustomEntities().Versions().UpdateDraftAsync(updateCmd); await scope.CompleteAsync(); } }