public async Task <CreateBrandResponse> Handle(CreateBrandRequest request, CancellationToken cancellationToken) { var newBrand = new Brand(request.BrandName); await _motoDatabaseContext.Brands.AddAsync(newBrand); await _motoDatabaseContext.SaveChangesAsync(); return(new CreateBrandResponse { BrandId = newBrand.BrandId }); }
public async Task <UpdateBrandResponse> Handle(UpdateBrandRequest request, CancellationToken cancellationToken) { var brand = await _motoDatabaseContext .Brands .Include(b => b.BrandDomainEvents) .SingleAsync(b => b.BrandId == request.BrandId, cancellationToken); if (!brand.BrandName.Equals(request.BrandName)) { brand.BrandName = request.BrandName; _motoDatabaseContext.BrandDomainEvents.Add(new BrandDomainEvent(CrossCutting.Enums.DomainEventType.Edit) { Brand = brand }); await _motoDatabaseContext.SaveChangesAsync(); } return(new UpdateBrandResponse()); }