public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, TenantUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.Name, p => p.Description, p => p.Slug, p => p.City, p => p.StateProvince, p => p.TimeZone, p => p.DomainName ); var updateCommand = new EntityUpdateCommand <Guid, TenantUpdateModel, TenantReadModel>(User, Id, updateModel); var result = await Mediator.Send(updateCommand); ShowAlert("Successfully saved tenant"); return(RedirectToPage("/Global/Tenant/Edit", new { id = result.Id })); }
protected override async Task <CompleteModel> Process(SignUpCommand request, CancellationToken cancellationToken) { var principal = request.Principal; var updateCommand = new EntityUpsertCommand <Guid, SignUpUpdateModel, SignUpReadModel>(principal, request.Id, request.InstructorSignUp); var updateModel = await _mediator.Send(updateCommand, cancellationToken); foreach (var signupTopic in request.InstructorSignUpTopics) { var signupTopicCommand = new EntityUpsertCommand <Guid, SignUpTopicUpdateModel, SignUpTopicReadModel>(principal, signupTopic.Id, signupTopic); var signupTopicModel = await _mediator.Send(signupTopicCommand, cancellationToken); var topicId = signupTopicModel.TopicId; var topicReadCommand = new EntityIdentifierQuery <Guid, TopicUpdateModel>(principal, topicId); var topicModel = await _mediator.Send(topicReadCommand, cancellationToken); topicModel.InstructorSlots = signupTopic.TopicInstructorSlots; var topicUpdateCommand = new EntityUpdateCommand <Guid, TopicUpdateModel, TopicReadModel>(principal, topicId, topicModel); var updatedModel = await _mediator.Send(topicUpdateCommand, cancellationToken); } return(new CompleteModel()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, DiscussionUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.Message ); var updateCommand = new EntityUpdateCommand <Guid, DiscussionUpdateModel, DiscussionReadModel>(User, Id, updateModel); var result = await Mediator.Send(updateCommand); ShowAlert("Successfully saved topic discussion message"); return(RedirectToPage("/Topic/Discussion/View", new { Id = TopicId, tenant = TenantRoute })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, InstructorUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.GivenName, p => p.FamilyName, p => p.DisplayName, p => p.JobTitle, p => p.EmailAddress, p => p.MobilePhone, p => p.BusinessPhone ); var updateCommand = new EntityUpdateCommand <Guid, InstructorUpdateModel, InstructorReadModel>(User, Id, updateModel); var result = await Mediator.Send(updateCommand); ShowAlert("Successfully saved instructor"); return(RedirectToPage("/Instructor/View", new { id = result.Id, tenant = TenantRoute })); }
protected override async Task <MemberReadModel> Process(EntityUpdateCommand <Guid, MemberUpdateModel, MemberReadModel> request, CancellationToken cancellationToken) { var id = request.Id; var model = request.Model; var user = await _userManager.FindByIdAsync(id.ToString()); if (user == null) { return(null); } if (string.IsNullOrEmpty(user.SecurityStamp)) { await _userManager.UpdateSecurityStampAsync(user); } bool isGlobalAdministrator = request.Principal.IsInRole(Data.Constants.Role.GlobalAdministrator); await UpdateEmail(id, model, user); await UpdatePhoneNumber(id, model, user); await UpdateModel(id, model, user, isGlobalAdministrator); await UpdateLockoutEnd(id, model, user); return(await Read(id, cancellationToken).ConfigureAwait(false)); }
protected virtual async Task <TReadModel> UpdateCommand(TKey id, TUpdateModel updateModel, CancellationToken cancellationToken = default(CancellationToken)) { var command = new EntityUpdateCommand <TKey, TUpdateModel, TReadModel>(id, updateModel, User); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); return(result); }
protected override async Task <TReadModel> Process(EntityUpdateCommand <TKey, TUpdateModel, TReadModel> request, CancellationToken cancellationToken) { var dbSet = DataContext .Set <TEntity>(); var keyValue = new object[] { request.Id }; // find entity to update by message id, not model id var entity = await dbSet .FindAsync(keyValue, cancellationToken) .ConfigureAwait(false); if (entity == null) { return(default(TReadModel)); } // copy updates from model to entity Mapper.Map(request.Model, entity); // save updates await DataContext .SaveChangesAsync(cancellationToken) .ConfigureAwait(false); // return read model var readModel = await Read(entity.Id, cancellationToken) .ConfigureAwait(false); return(readModel); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, TopicUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.Title, p => p.Description, p => p.CalendarYear, p => p.TargetMonth, p => p.LeadInstructorId, p => p.IsRequired ); var updateCommand = new EntityUpdateCommand <Guid, TopicUpdateModel, TopicReadModel>(User, Id, updateModel); var result = await Mediator.Send(updateCommand); ShowAlert("Successfully saved topic"); return(RedirectToPage("/Topic/View", new { id = result.Id, tenant = TenantRoute })); }
private async Task <PaymentReadModel> PaymentTransaction(Guid attendeeId, Guid oldCourse, Guid newCourse, CancellationToken cancellationToken) { var search = Query <Data.Entities.PaymentTransaction> .Create(x => x.UserProfileId == attendeeId); search = search.And(Query <Data.Entities.PaymentTransaction> .Create(x => x.CourseId == oldCourse)); var query = new SingleQuery <Data.Entities.PaymentTransaction>(search); var command = new EntitySingleQuery <Data.Entities.PaymentTransaction, PaymentReadModel>(query); var result = await _mediator.Send(command, cancellationToken).ConfigureAwait(false); var map = _mapper.Map <PaymentUpdateModel>(result.Data); map.CourseId = newCourse; var updatecommand = new EntityUpdateCommand <Guid, PaymentTransaction, PaymentUpdateModel, PaymentReadModel>(result.Data.Id, map, null); var output = await _mediator.Send(updatecommand, cancellationToken).ConfigureAwait(false); var historymap = _mapper.Map <PaymentHistoryCreateModel>(result.Data); var createcommand = new EntityCreateCommand <Data.Entities.PaymentTransactionHistory, PaymentHistoryCreateModel, PaymentHistoryReadModel>(historymap, null); await _mediator.Send(createcommand, cancellationToken).ConfigureAwait(false); return(output); }
protected override async Task <TReadModel> ProcessAsync(EntityUpdateCommand <TKey, TEntity, TUpdateModel, TReadModel> message, CancellationToken cancellationToken) { var dbSet = _context .Set <TEntity>(); var keyValue = new object[] { message.Id }; // find entity to update by message id, not model id var entity = await dbSet .FindAsync(keyValue, cancellationToken) .ConfigureAwait(false); if (entity == null) { return(default(TReadModel)); } // save original for later pipeline processing message.Original = _mapper.Map <TReadModel>(entity); // copy updates from model to entity _mapper.Map(message.Model, entity); // save updates await _context .SaveChangesAsync(cancellationToken) .ConfigureAwait(false); // return read model var readModel = _mapper.Map <TReadModel>(entity); return(readModel); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, LocationUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.Name, p => p.Description, p => p.AddressLine1, p => p.City, p => p.StateProvince, p => p.PostalCode ); var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(User, Id, updateModel); var result = await Mediator.Send(updateCommand); ShowAlert("Successfully saved location"); return(RedirectToPage("/Location/Edit", new { id = result.Id, tenant = TenantRoute })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, MemberUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.DisplayName, p => p.SortName, p => p.FamilyName, p => p.GivenName, p => p.JobTitle, p => p.Email, p => p.PhoneNumber ); // compute sort name if (updateModel.SortName.IsNullOrWhiteSpace()) { updateModel.SortName = ToSortName(updateModel); } if (IsMemberDisabled && updateModel.LockoutEnd == null) { updateModel.LockoutEnd = DateTimeOffset.Now.AddYears(100); } else if (!IsMemberDisabled && updateModel.LockoutEnd.HasValue) { updateModel.LockoutEnd = null; } var updateCommand = new EntityUpdateCommand <Guid, MemberUpdateModel, MemberReadModel>(User, Id, updateModel); var updateResult = await Mediator.Send(updateCommand); // make sure correct user and tenant Membership.UserId = updateResult.Id; Membership.TenantId = Tenant.Value.Id; var membershipCommand = new TenantMembershipCommand(User, Membership); var membershipResult = await Mediator.Send(membershipCommand); ShowAlert("Successfully saved member"); return(RedirectToPage("/Member/Edit", new { id = Id, tenant = TenantRoute })); }
private async Task <CourseReadModel> UpdateOldCourse(CourseReadModel result, CancellationToken cancellationToken) { var oldCourse = _mapper.Map <CourseUpdateModel>(result); oldCourse.MaxAttendee = oldCourse.MaxAttendee + 1; oldCourse.NoAttendee = oldCourse.NoAttendee - 1; var commandOldCourse = new EntityUpdateCommand <Guid, Data.Entities.TrainingCourse, CourseUpdateModel, CourseReadModel>(result.Id, oldCourse, null); return(await _mediator.Send(commandOldCourse, cancellationToken).ConfigureAwait(false)); }
private async Task <TrainingBuildCoursesAttendeeReadModel> UpdateOldAttendee( TrainingBuildCoursesAttendeeReadModel message, Guid id, CancellationToken cancellationToken) { var map = _mapper.Map <TrainingBuildCoursesAttendeeUpdateModel>(message); var command = new EntityUpdateCommand <Guid, Data.Entities.TrainingBuildCourseAttendee, TrainingBuildCoursesAttendeeUpdateModel, TrainingBuildCoursesAttendeeReadModel>(id, map, null); return(await _mediator.Send(command, cancellationToken).ConfigureAwait(false)); }
protected override async Task <PaymentReadModel> ProcessAsync(PaymentApprovalCommand <Guid, PaymentTransaction, PaymentReadModel> message, CancellationToken cancellationToken) { var command = new EntityIdentifierQuery <Guid, PaymentTransaction, PaymentReadModel>(message.Id, message.Principal); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); if (result == null) { throw new DomainException(422, $"Payment Id '{message.Id}' not found."); } if (result.Status != message.PaymentStatus) { var commandCourse = new EntityIdentifierQuery <Guid, TrainingCourse, CourseReadModel>(result.CourseId.Value, message.Principal); var resultCourse = await Mediator.Send(commandCourse, cancellationToken).ConfigureAwait(false); if (resultCourse == null) { throw new DomainException(422, $"Course Id '{result.CourseId}' not found."); } if (resultCourse.MaxAttendee == resultCourse.NoAttendee) { throw new DomainException(422, $"Course '{resultCourse.Title}' is already full."); } var mapCourse = _mapper.Map <CourseUpdateModel>(resultCourse); mapCourse.MaxAttendee = mapCourse.MaxAttendee - 1; mapCourse.NoAttendee = mapCourse.NoAttendee + 1; var updateCourse = new EntityUpdateCommand <Guid, TrainingCourse, CourseUpdateModel, CourseReadModel>(resultCourse.Id, mapCourse, message.Principal); var mediatorCourse = await Mediator.Send(updateCourse, cancellationToken) .ConfigureAwait(false); result.Status = message.PaymentStatus; var map = _mapper.Map <PaymentUpdateModel>(result); var update = new EntityUpdateCommand <Guid, PaymentTransaction, PaymentUpdateModel, PaymentReadModel>(message.Id, map, message.Principal); result = await Mediator.Send(update, cancellationToken).ConfigureAwait(false); var history = _mapper.Map <PaymentTransactionHistory>(result); var dbSetHistory = _dataContext.Set <Data.Entities.PaymentTransactionHistory>(); await dbSetHistory.AddAsync(history, cancellationToken).ConfigureAwait(false); await _dataContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); var mapAttendee = _mapper.Map <TrainingBuildCoursesAttendeeCreatedModel>(result); var courseAttendee = new EntityCreateCommand <Core.Data.Entities.TrainingBuildCourseAttendee, TrainingBuildCoursesAttendeeCreatedModel, TrainingBuildCoursesAttendeeReadModel>(mapAttendee, message.Principal); var resultCourseAttendee = await Mediator.Send(courseAttendee, cancellationToken).ConfigureAwait(false); } return(result); }
private async Task <CourseReadModel> AddToNewCourse(CourseReadModel resultQueryNewCourse, CancellationToken cancellationToken ) { var mapnewCourse = _mapper.Map <CourseUpdateModel>(resultQueryNewCourse); mapnewCourse.MaxAttendee = mapnewCourse.MaxAttendee - 1; mapnewCourse.NoAttendee = mapnewCourse.NoAttendee + 1; var command = new EntityUpdateCommand <Guid, Data.Entities.TrainingCourse, CourseUpdateModel, CourseReadModel>(resultQueryNewCourse.Id, mapnewCourse, null); return(await _mediator.Send(command, cancellationToken).ConfigureAwait(false)); }
protected override async Task <TReadModel> Process(EntityUpdateCommand <TKey, TUpdateModel, TReadModel> request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var entity = await Repository .FindAsync(request.Id, cancellationToken) .ConfigureAwait(false); if (entity == null) { return(default !);
protected override async Task <TReadModel> Process(EntityUpdateCommand <TKey, TUpdateModel, TReadModel> request, CancellationToken cancellationToken) { var dbSet = DataContext .Set <TEntity>(); var keyValue = new object[] { request.Id }; // find entity to update by message id, not model id var entity = await dbSet .FindAsync(keyValue, cancellationToken) .ConfigureAwait(false); if (entity == null) { return(default);
public CommandStatus Handle(EntityUpdateCommand <T> command) { EntityUpdateCommandData <T> _data = GetData(); bool ret; try { ret = _data.Update(command.Entity); return(new Success()); } catch (Exception ex) { // Notify, log return(new Failure(ex.Message)); } }
protected override async Task <TReadModel> Process(EntityUpdateCommand <string, TUpdateModel, TReadModel> request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } if (!CosmosKey.TryDecode(request.Id, out var id, out var partitionKey)) { throw new InvalidOperationException("Invalid Cosmos Key format"); } var entity = await Repository .FindAsync(id, partitionKey, cancellationToken) .ConfigureAwait(false); if (entity == null) { return(default !);
public void ConstructorWithModel() { var id = Guid.NewGuid(); var updateModel = Generator.Default.Single <LocationUpdateModel>(); updateModel.Should().NotBeNull(); var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(MockPrincipal.Default, id, updateModel); updateCommand.Should().NotBeNull(); updateCommand.Id.Should().NotBe(Guid.Empty); updateCommand.Id.Should().Be(id); updateCommand.Model.Should().NotBeNull(); updateCommand.Principal.Should().NotBeNull(); }
public async Task UpdateLocation() { var original = Generator.Default.Single <Location>(); var config = new MapperConfiguration(cfg => { cfg.CreateMap <LocationCreateModel, Location>(); cfg.CreateMap <LocationUpdateModel, Location>(); cfg.CreateMap <Location, LocationReadModel>(); }); var mapper = new Mapper(config); var options = new DbContextOptionsBuilder <SampleContext>() .UseInMemoryDatabase(databaseName: "UpdateLocation") .Options; var context = new SampleContext(options); context.Locations.Add(original); context.SaveChanges(); var updateModel = Generator.Default.Single <LocationUpdateModel>(); updateModel.Should().NotBeNull(); var updateCommand = new EntityUpdateCommand <Guid, LocationUpdateModel, LocationReadModel>(MockPrincipal.Default, original.Id, updateModel); updateCommand.Should().NotBeNull(); updateCommand.Model.Should().NotBeNull(); updateCommand.Principal.Should().NotBeNull(); var updateCommandHandler = new EntityUpdateCommandHandler <SampleContext, Location, Guid, LocationUpdateModel, LocationReadModel>(NullLoggerFactory.Instance, context, mapper); var readModel = await updateCommandHandler.Handle(updateCommand, CancellationToken.None); readModel.Should().NotBeNull(); readModel.Id.Should().NotBe(Guid.Empty); readModel.Id.Should().Be(original.Id); readModel.Name.Should().Be(updateModel.Name); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, SessionUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.Note, p => p.StartDate, p => p.StartTime, p => p.EndDate, p => p.EndTime, p => p.LocationId, p => p.GroupId, p => p.LeadInstructorId ); var updateCommand = new EntityUpdateCommand <Guid, SessionUpdateModel, SessionReadModel>(User, Id, updateModel); var result = await Mediator.Send(updateCommand); var instructorCommand = new SessionInstructorUpdateCommand(User, Id, AdditionalInstructors); await Mediator.Send(instructorCommand); ShowAlert("Successfully saved topic session"); return(RedirectToPage("/Topic/Session/View", new { result.Id, TopicId, tenant = TenantRoute })); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var readCommand = new EntityIdentifierQuery <Guid, MemberUpdateModel>(User, Id); var updateModel = await Mediator.Send(readCommand); if (updateModel == null) { return(NotFound()); } // only update input fields await TryUpdateModelAsync( updateModel, nameof(Entity), p => p.DisplayName, p => p.Email, p => p.PhoneNumber ); var updateCommand = new EntityUpdateCommand <Guid, MemberUpdateModel, MemberReadModel>(User, Id, updateModel); var updateResult = await Mediator.Send(updateCommand); // make sure correct user and tenant Membership.UserName = updateResult.UserName; Membership.TenantId = Tenant.Value.Id; var membershipCommand = new TenantMembershipCommand(User, Membership); var membershipResult = await Mediator.Send(membershipCommand); ShowAlert("Successfully saved member"); return(RedirectToPage("/Member/Edit", new { id = Id, tenant = TenantRoute })); }
public async Task <IActionResult> Update(CancellationToken cancellationToken, ProductUpdateDto model, int id) { var returnResponse = new EntityResponseModel <ProductReadDto>(); try { var command = new EntityUpdateCommand <int, ProductUpdateDto, EntityResponseModel <ProductReadDto> >(id, model); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); if (result.ReturnStatus == false) { return(BadRequest(result)); } return(Ok(result)); } catch (Exception ex) { returnResponse.ReturnStatus = false; returnResponse.ReturnMessage.Add(ex.Message); return(BadRequest(returnResponse)); } }
public async Task FullTest() { var mediator = ServiceProvider.GetService <IMediator>(); mediator.Should().NotBeNull(); var mapper = ServiceProvider.GetService <IMapper>(); mapper.Should().NotBeNull(); // Create Entity var createModel = Generator.Default.Single <TenantCreateModel>(); createModel.Slug = "Test" + DateTime.Now.Ticks; createModel.TimeZone = "Central Standard Time"; var createCommand = new EntityCreateCommand <TenantCreateModel, TenantReadModel>(MockPrincipal.Default, createModel); var createResult = await mediator.Send(createCommand).ConfigureAwait(false); createResult.Should().NotBeNull(); // Get Entity by Key var identifierQuery = new EntityIdentifierQuery <Guid, TenantReadModel>(MockPrincipal.Default, createResult.Id); var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false); identifierResult.Should().NotBeNull(); identifierResult.Name.Should().Be(createModel.Name); // Query Entity var entityQuery = new EntityQuery { Sort = new[] { new EntitySort { Name = "Updated", Direction = "Descending" } }, Filter = new EntityFilter { Name = "Slug", Value = "TEST" } }; var listQuery = new EntityPagedQuery <TenantReadModel>(MockPrincipal.Default, entityQuery); var listResult = await mediator.Send(listQuery).ConfigureAwait(false); listResult.Should().NotBeNull(); // Patch Entity var patchModel = new JsonPatchDocument <Tenant>(); patchModel.Operations.Add(new Operation <Tenant> { op = "replace", path = "/Description", value = "Patch Update" }); var patchCommand = new EntityPatchCommand <Guid, TenantReadModel>(MockPrincipal.Default, createResult.Id, patchModel); var patchResult = await mediator.Send(patchCommand).ConfigureAwait(false); patchResult.Should().NotBeNull(); patchResult.Description.Should().Be("Patch Update"); // Update Entity var updateModel = mapper.Map <TenantUpdateModel>(patchResult); updateModel.Description = "Update Command"; var updateCommand = new EntityUpdateCommand <Guid, TenantUpdateModel, TenantReadModel>(MockPrincipal.Default, createResult.Id, updateModel); var updateResult = await mediator.Send(updateCommand).ConfigureAwait(false); updateResult.Should().NotBeNull(); updateResult.Description.Should().Be("Update Command"); // Delete Entity var deleteCommand = new EntityDeleteCommand <Guid, TenantReadModel>(MockPrincipal.Default, createResult.Id); var deleteResult = await mediator.Send(deleteCommand).ConfigureAwait(false); deleteResult.Should().NotBeNull(); deleteResult.Id.Should().Be(createResult.Id); }
public async Task FullTest() { var mediator = ServiceProvider.GetService <IMediator>(); mediator.Should().NotBeNull(); var mapper = ServiceProvider.GetService <IMapper>(); mapper.Should().NotBeNull(); // Create Entity var createModel = Generator.Default.Single <TaskCreateModel>(); createModel.Id = ObjectId.GenerateNewId().ToString(); createModel.Title = "Testing"; createModel.Description = "Test " + DateTime.Now.Ticks; createModel.StatusId = StatusConstants.NotStarted.Id; createModel.TenantId = TenantConstants.Test.Id; var createCommand = new EntityCreateCommand <TaskCreateModel, TaskReadModel>(MockPrincipal.Default, createModel); var createResult = await mediator.Send(createCommand).ConfigureAwait(false); createResult.Should().NotBeNull(); // Get Entity by Key var key = createResult.Id; var identifierQuery = new EntityIdentifierQuery <string, TaskReadModel>(MockPrincipal.Default, key); var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false); identifierResult.Should().NotBeNull(); identifierResult.Title.Should().Be(createModel.Title); // Query Entity var entityQuery = new EntityQuery { Sort = new List <EntitySort> { new EntitySort { Name = "Updated", Direction = "Descending" } }, Filter = new EntityFilter { Name = "StatusId", Value = StatusConstants.NotStarted.Id } }; var listQuery = new EntityPagedQuery <TaskReadModel>(MockPrincipal.Default, entityQuery); var listResult = await mediator.Send(listQuery).ConfigureAwait(false); listResult.Should().NotBeNull(); // Patch Entity var patchModel = new JsonPatchDocument <Task>(); patchModel.Operations.Add(new Operation <Task> { op = "replace", path = "/Title", value = "Patch Update" }); var patchCommand = new EntityPatchCommand <string, TaskReadModel>(MockPrincipal.Default, key, patchModel); var patchResult = await mediator.Send(patchCommand).ConfigureAwait(false); patchResult.Should().NotBeNull(); patchResult.Title.Should().Be("Patch Update"); // Update Entity var updateModel = mapper.Map <TaskUpdateModel>(patchResult); updateModel.Title = "Update Command"; var updateCommand = new EntityUpdateCommand <string, TaskUpdateModel, TaskReadModel>(MockPrincipal.Default, key, updateModel); var updateResult = await mediator.Send(updateCommand).ConfigureAwait(false); updateResult.Should().NotBeNull(); updateResult.Title.Should().Be("Update Command"); // Delete Entity var deleteCommand = new EntityDeleteCommand <string, TaskReadModel>(MockPrincipal.Default, key); var deleteResult = await mediator.Send(deleteCommand).ConfigureAwait(false); deleteResult.Should().NotBeNull(); deleteResult.Id.Should().Be(createResult.Id); }
public async Task FullTest() { var mediator = ServiceProvider.GetService <IMediator>(); mediator.Should().NotBeNull(); var mapper = ServiceProvider.GetService <IMapper>(); mapper.Should().NotBeNull(); // Create Entity var createModel = Generator.Default.Single <InstructorCreateModel>(); createModel.TenantId = Data.Constants.Tenant.Test; createModel.DisplayName = $"{createModel.GivenName} {createModel.FamilyName}"; createModel.JobTitle = "TEST"; var createCommand = new EntityCreateCommand <InstructorCreateModel, InstructorReadModel>(MockPrincipal.Default, createModel); var createResult = await mediator.Send(createCommand).ConfigureAwait(false); createResult.Should().NotBeNull(); // Get Entity by Key var identifierQuery = new EntityIdentifierQuery <Guid, InstructorReadModel>(MockPrincipal.Default, createResult.Id); var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false); identifierResult.Should().NotBeNull(); identifierResult.DisplayName.Should().Be(createModel.DisplayName); // Query Entity var entityQuery = new EntityQuery { Sort = new[] { new EntitySort { Name = "Updated", Direction = "Descending" } }, Filter = new EntityFilter { Name = "JobTitle", Value = "TEST" } }; var listQuery = new EntityPagedQuery <InstructorReadModel>(MockPrincipal.Default, entityQuery); var listResult = await mediator.Send(listQuery).ConfigureAwait(false); listResult.Should().NotBeNull(); // Patch Entity var patchModel = new JsonPatchDocument <Instructor>(); patchModel.Operations.Add(new Operation <Instructor> { op = "replace", path = "/DisplayName", value = "Patch Update" }); var patchCommand = new EntityPatchCommand <Guid, InstructorReadModel>(MockPrincipal.Default, createResult.Id, patchModel); var patchResult = await mediator.Send(patchCommand).ConfigureAwait(false); patchResult.Should().NotBeNull(); patchResult.DisplayName.Should().Be("Patch Update"); // Update Entity var updateModel = mapper.Map <InstructorUpdateModel>(patchResult); updateModel.DisplayName = "Update Command"; var updateCommand = new EntityUpdateCommand <Guid, InstructorUpdateModel, InstructorReadModel>(MockPrincipal.Default, createResult.Id, updateModel); var updateResult = await mediator.Send(updateCommand).ConfigureAwait(false); updateResult.Should().NotBeNull(); updateResult.DisplayName.Should().Be("Update Command"); // Delete Entity var deleteCommand = new EntityDeleteCommand <Guid, InstructorReadModel>(MockPrincipal.Default, createResult.Id); var deleteResult = await mediator.Send(deleteCommand).ConfigureAwait(false); deleteResult.Should().NotBeNull(); deleteResult.Id.Should().Be(createResult.Id); }
protected override async Task <TReadModel> Process(EntityUpdateCommand <TKey, TEntity, TUpdateModel, TReadModel> request, CancellationToken cancellationToken, RequestHandlerDelegate <TReadModel> next) { // continue pipeline return(await next().ConfigureAwait(false)); }
public async Task FullTest() { var mediator = ServiceProvider.GetService <IMediator>(); mediator.Should().NotBeNull(); var mapper = ServiceProvider.GetService <IMapper>(); mapper.Should().NotBeNull(); // Create Entity var createModel = Generator.Default.Single <AuditCreateModel>(); createModel.Username = "******"; createModel.Content = "Test " + DateTime.Now.Ticks; var createCommand = new EntityCreateCommand <AuditCreateModel, AuditReadModel>(MockPrincipal.Default, createModel); var createResult = await mediator.Send(createCommand).ConfigureAwait(false); createResult.Should().NotBeNull(); // Get Entity by Key var key = CosmosKey.Encode(createResult.Id, createResult.Id); var identifierQuery = new EntityIdentifierQuery <string, AuditReadModel>(MockPrincipal.Default, key); var identifierResult = await mediator.Send(identifierQuery).ConfigureAwait(false); identifierResult.Should().NotBeNull(); identifierResult.Username.Should().Be(createModel.Username); // Query Entity var entityQuery = new EntityQuery { Sort = new List <EntitySort> { new EntitySort { Name = "Updated", Direction = "Descending" } }, Filter = new EntityFilter { Name = "Username", Value = "TEST" } }; var listQuery = new EntityPagedQuery <AuditReadModel>(MockPrincipal.Default, entityQuery); var listResult = await mediator.Send(listQuery).ConfigureAwait(false); listResult.Should().NotBeNull(); // Patch Entity var patchModel = new JsonPatchDocument <Audit>(); patchModel.Operations.Add(new Operation <Audit> { op = "replace", path = "/Content", value = "Patch Update" }); var patchCommand = new EntityPatchCommand <string, AuditReadModel>(MockPrincipal.Default, key, patchModel); var patchResult = await mediator.Send(patchCommand).ConfigureAwait(false); patchResult.Should().NotBeNull(); patchResult.Content.Should().Be("Patch Update"); // Update Entity var updateModel = mapper.Map <AuditUpdateModel>(patchResult); updateModel.Content = "Update Command"; var updateCommand = new EntityUpdateCommand <string, AuditUpdateModel, AuditReadModel>(MockPrincipal.Default, key, updateModel); var updateResult = await mediator.Send(updateCommand).ConfigureAwait(false); updateResult.Should().NotBeNull(); updateResult.Content.Should().Be("Update Command"); // Delete Entity var deleteCommand = new EntityDeleteCommand <string, AuditReadModel>(MockPrincipal.Default, key); var deleteResult = await mediator.Send(deleteCommand).ConfigureAwait(false); deleteResult.Should().NotBeNull(); deleteResult.Id.Should().Be(createResult.Id); }