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(ApproveBookingCommand 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.Approved; booking.IsApproved = true; booking.IsCancelled = false; await booking.AddLogEntry(CurrentUserProvider, "Reservationen blev godkendt."); 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(AnonymizeBookingsCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityDeletePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); var query = new SearchBookingSummariesQuery { BookingState = new BookingDataModel.BookingStateType[] { BookingDataModel.BookingStateType.Closed }, Start = new DateTime(2000, 1, 1), End = DateTime.Now.AddYears(-3) }; command.AnonymizedCount = 0; foreach (KeyValuePair <int, BookingDataModel> bookingEntry in (await BookingProvider.FindBookingDataInInterval(query)).ToList()) { BookingDataModel booking = bookingEntry.Value; // Protected agains mistakes in the query by checking values again if (!booking.IsArchived && booking.BookingState == BookingDataModel.BookingStateType.Closed && booking.DepartureDate.Value.AddYears(3) < DateTime.Now) { booking.TenantName = "---"; booking.Purpose = "---"; booking.ContactName = "---"; booking.ContactEMail = "ukendt@ukendte-mailmodtagere"; booking.ContactPhone = "---"; booking.ContactAddress = "---"; booking.ContactCity = "---"; booking.Comments = "---"; foreach (var document in booking.Documents) { var deleteDocumentCommand = new DeleteDocumentCommand { Id = document.DocumentId }; await CommandExecutor.ExecuteAsync(deleteDocumentCommand); } booking.LogEntries.Clear(); booking.Documents.Clear(); booking.IsArchived = true; command.AnonymizedCount++; UpdateCustomEntityDraftVersionCommand updateCmd = new UpdateCustomEntityDraftVersionCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, CustomEntityId = bookingEntry.Key, Title = booking.MakeTitle(), Publish = true, Model = booking }; await DomainRepository.CustomEntities().Versions().UpdateDraftAsync(updateCmd); } } }
public async Task <IActionResult> Test() { var entity = await _contentRepository .CustomEntities() .GetByUrlSlug <ExampleCustomEntityDefinition>("test") .AsRenderSummaries() .ExecuteAsync(); return(Json(entity)); }
private static async Task AddCustomEntity(TestCustomEntityInfo customEntity, IAdvancedContentRepository contentRepository) { customEntity.CustomEntityId = await contentRepository .CustomEntities() .AddAsync(new AddCustomEntityCommand() { CustomEntityDefinitionCode = customEntity.CustomEntityDefinitionCode, Model = new TestCustomEntityDataModel(), Publish = true, Title = customEntity.Title, UrlSlug = customEntity.UrlSlug }); }
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 ExecuteAsync(SendBookingMailCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityUpdatePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); using (var scope = DomainRepository.Transactions().CreateScope()) { BookingDataModel booking = await BookingProvider.GetBookingById(command.BookingId); await booking.AddLogEntry(CurrentUserProvider, $"Sendt: {command.Subject}."); byte[] mailBody = System.Text.Encoding.UTF8.GetBytes(command.Message); var addDcoumentCommand = new AddDocumentCommand { Title = command.Subject, MimeType = "text/html", Body = mailBody }; await CommandExecutor.ExecuteAsync(addDcoumentCommand); booking.AddDocument(command.Subject, addDcoumentCommand.OutputDocumentId); UpdateCustomEntityDraftVersionCommand updateCmd = new UpdateCustomEntityDraftVersionCommand { CustomEntityDefinitionCode = BookingCustomEntityDefinition.DefinitionCode, CustomEntityId = command.BookingId, Title = booking.MakeTitle(), Publish = true, Model = booking }; await DomainRepository.CustomEntities().Versions().UpdateDraftAsync(updateCmd); MailAddress to = new MailAddress(booking.ContactEMail, booking.ContactName); MailMessage message = new MailMessage { To = to, Subject = command.Subject, HtmlBody = command.Message }; // It is not really a good idea to contact a mail server during a transaction, but ... // 1) I really don't want the mail being registered in the database as "sent" if the mail sending fails. // 2) One can hope that the dispatcher simply adds the message to an outgoing mail queue. // (and, yes, sending mails may fail much later with an "unknown recipient" or similar) await MailDispatchService.DispatchAsync(message); await scope.CompleteAsync(); } }
public async Task<IActionResult> Test2() { await _domainRepository .WithElevatedPermissions() .ExecuteQueryAsync(new GetCustomEntityDataModelSchemaDetailsByDefinitionCodeQuery("")); var entity = await _contentRepository .WithElevatedPermissions() .CustomEntities() .GetById(1) .AsRenderSummary(PublishStatusQuery.Published) .ExecuteAsync(); var entities = await _contentRepository .CustomEntities() .GetByDefinitionCode("") .AsRenderSummary(PublishStatusQuery.Published) .MapItem(e => new { e.Title }) .ExecuteAsync(); var enity2 = await _contentRepository .CustomEntities() .GetById(1) .AsRenderSummary(PublishStatusQuery.Published) .Map(e => new Dictionary<string, string>()) .ExecuteAsync(); var ids = new int[] { 1 }; var catCustomEntities = await _contentRepository .CustomEntities() .GetByIdRange(ids) .AsRenderSummaries() //.MapItem(i => new { i.UrlSlug, i.Title }) .MapItem(MapCatAsync) .FilterAndOrderByKeys(ids) .Map(v => v.OrderBy(v => v.Title)) .ExecuteAsync(); var customExecution = await _domainRepository .WithQuery(new SearchCustomEntityRenderSummariesQuery()) .MapItem(b => new { b.CreateDate }) .ExecuteAsync(); return Json(entity); }
public async Task ExecuteAsync(DeleteBookingCommand command, IExecutionContext executionContext) { PermissionValidationService.EnforceCustomEntityPermission <CustomEntityDeletePermission>(BookingCustomEntityDefinition.DefinitionCode, executionContext.UserContext); using (var scope = DomainRepository.Transactions().CreateScope()) { var booking = await BookingProvider.GetBookingById(command.Id); foreach (var document in booking.Documents) { var deleteDocumentCommand = new DeleteDocumentCommand { Id = document.DocumentId }; await CommandExecutor.ExecuteAsync(deleteDocumentCommand); } await DomainRepository.CustomEntities().DeleteAsync(command.Id); 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(); } }
public async Task <IActionResult> Test() { var user = await _contentRepository .WithElevatedPermissions() .Users() .GetById(2) .AsMicroSummaryAsync(); var image = await _contentRepository .ImageAssets() .GetById(2) .AsRenderDetailsAsync(); var page = await _contentRepository .Pages() .Search() .AsRenderSummariesAsync(new SearchPageRenderSummariesQuery() { PageSize = 20, PageDirectoryId = 2 }); var page2 = await _contentRepository .Pages() .GetById(1) .AsRenderSummaryAsync(); // Perhaps NotFound should look like this: await _contentRepository .Pages() .NotFound() .GetByPathAsync(new GetNotFoundPageRouteByPathQuery()); var regions = await _contentRepository .Pages() .Versions() .Regions() .Blocks() .GetById(2) .AsRenderDetailsAsync(PublishStatusQuery.Latest); await _contentRepository .Pages() .GetByPath() .AsRoutingInfo(new GetPageRoutingInfoByPathQuery()); //.PublishAsync(new PublishPageCommand() { PageId = 2 }); var isUnique = await _contentRepository .Users() .IsUsernameUniqueAsync(new IsUsernameUniqueQuery() { UserAreaCode = CofoundryAdminUserArea.AreaCode, Username = "******" }); int userId; using (var scope = _contentRepository.Transactions().CreateScope()) { var adminRole = await _contentRepository .Roles() .GetByCode(SuperAdminRole.SuperAdminRoleCode) .AsDetailsAsync(); userId = await _contentRepository .WithElevatedPermissions() .Users() .AddAsync(new AddUserCommand() { Email = Guid.NewGuid().ToString() + "@cofoundry.org", Password = "******", UserAreaCode = CofoundryAdminUserArea.AreaCode, RoleId = adminRole.RoleId }); //await _contentRepository // .WithElevatedPermissions() // .ImageAssets() // .DeleteAsync(2); await _contentRepository .CustomEntities() .Definitions() .GetByCode(BlogPostCustomEntityDefinition.DefinitionCode) .AsSummaryAsync(); await _contentRepository .CustomEntities() .DataModelSchemas() .GetByCustomEntityDefinitionCode(BlogPostCustomEntityDefinition.DefinitionCode) .AsDetailsAsync(); await _contentRepository .CustomEntities() .GetById(1) .AsRenderSummaryAsync(); var permissions = await _contentRepository .Roles() .Permissions() .GetAll() .AsIPermissionAsync(); var directoryTree = await _contentRepository .PageDirectories() .GetAll() .AsTreeAsync(); var rewriteRules = await _contentRepository .RewriteRules() .GetAll() .AsSummariesAsync(); var blockTypes = await _contentRepository .PageBlockTypes() .GetAll() .AsSummariesAsync(); await scope.CompleteAsync(); } await _contentRepository .WithElevatedPermissions() .Users() .DeleteUserAsync(userId); return(View()); }