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); }
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); }
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); }
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); }
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); }
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); }
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); }