コード例 #1
0
            public async Task <Unit> Handle(DeleteCommand request,
                                            CancellationToken cancellationToken)
            {
                var fined = await _context.Products
                            .Where(product => product.ProductId == request.ProductId)
                            .FirstOrDefaultAsync(cancellationToken);

                #region Work with dependencies

                await ClearProductPhotosAsync(request, cancellationToken);

                #endregion

                _context.Products.Remove(fined);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
                //return _mapper.Map<ProductLookupDto>(fined);
            }
コード例 #2
0
            public async Task <Unit> Handle(CreateCommand request,
                                            CancellationToken cancellationToken)
            {
                var result = await _context.Manufacturers
                             .AddAsync(new Manufacturer { Name = request.Name }, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
                // return _mapper.Map<ManufacturerLookupDto>(result.Entity);
            }
コード例 #3
0
            public async Task <Unit> Handle(CreateCommand request,
                                            CancellationToken cancellationToken)
            {
                var result = await _context.ProductPhotos.AddAsync(
                    new ProductPhoto { ProductId = request.ProductId, Path = request.Path }, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
                // return _mapper.Map<ProductPhotoLookupDto>(result.Entity);
            }
コード例 #4
0
            public async Task <Unit> Handle(DeleteCommand request, CancellationToken cancellationToken)
            {
                var fined = await _context.Manufacturers
                            .Where(e => e.ManufacturerId == request.ManufacturerId)
                            .FirstOrDefaultAsync(cancellationToken);

                _context.Manufacturers.Remove(fined);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
                // return _mapper.Map<ManufacturerLookupDto>(fined);
            }
コード例 #5
0
            public async Task <Unit> Handle(CreateCommand request, CancellationToken cancellationToken)
            {
                var result = await _context.Products.AddAsync(new Product
                {
                    ManufacturerId = request.Manufacturer.ManufacturerId,
                    Name           = request.Name,
                    ProductNumber  = request.ProductNumber
                }, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
                //return _mapper.Map<ProductLookupDto>(result.Entity);
            }
コード例 #6
0
            public async Task <Unit> Handle(UpdateCommand request,
                                            CancellationToken cancellationToken)
            {
                var fined = await _context.Manufacturers
                            .Where(e => e.ManufacturerId == request.ManufacturerId)
                            .FirstOrDefaultAsync(cancellationToken);

                fined.Name = request.Name;
                await _context.SaveChangesAsync(cancellationToken);

                await _mediator.Publish(new ManufacturerUpdated { ManufacturerId = fined.ManufacturerId },
                                        cancellationToken);

                return(Unit.Value);
            }
コード例 #7
0
            public async Task <Unit> Handle(UpdateCommand request,
                                            CancellationToken cancellationToken)
            {
                var fined = await _context.Products
                            .Where(e => e.ProductId == request.ProductId)
                            .FirstOrDefaultAsync(cancellationToken);

                fined.Manufacturer = await _context.Manufacturers
                                     .Where(e => e.ManufacturerId == request.Manufacturer.ManufacturerId)
                                     .FirstOrDefaultAsync(cancellationToken);

                fined.Name          = request.Name;
                fined.ProductNumber = request.ProductNumber;
                _context.Products.Update(fined);
                await _context.SaveChangesAsync(cancellationToken);

                return(Unit.Value);
                //return _mapper.Map<ProductLookupDto>(fined);
            }