Пример #1
0
            public async Task <CategoryLookupDto> Handle(CreateCategoryCommand request,
                                                         CancellationToken cancellationToken)
            {
                var result = await _context.Category.AddAsync(new Category { CategoryName = request.CategoryName },
                                                              cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(_mapper.Map <CategoryLookupDto>(result.Entity));
            }
Пример #2
0
            public async Task <GoodDto> Handle(DeleteGoodCommand request, CancellationToken cancellationToken)
            {
                var fined = await _context.Good
                            .Where(good => good.GoodId == request.GoodId)
                            .FirstOrDefaultAsync(cancellationToken);

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

                return(_mapper.Map <GoodDto>(fined));
            }
            public async Task <ManufacturerLookupDto> Handle(CreateManufacturerCommand request,
                                                             CancellationToken cancellationToken)
            {
                var result =
                    await _context.Manufacturer.AddAsync(new Manufacturer { ManufacturerName = request.ManufacturerName },
                                                         cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(_mapper.Map <ManufacturerLookupDto>(result.Entity));
            }
Пример #4
0
            public async Task <CategoryLookupDto> Handle(DeleteCategoryCommand request,
                                                         CancellationToken cancellationToken)
            {
                var fined = await _context.Category
                            .Where(category => category.CategoryId == request.CategoryId)
                            .FirstOrDefaultAsync(cancellationToken);

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

                return(_mapper.Map <CategoryLookupDto>(fined));
            }
            public async Task <ManufacturerLookupDto> Handle(DeleteManufacturerCommand request,
                                                             CancellationToken cancellationToken)
            {
                var fined = await _context.Manufacturer
                            .Where(manufacturer => manufacturer.ManufacturerId == request.ManufacturerId)
                            .FirstOrDefaultAsync(cancellationToken);

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

                return(_mapper.Map <ManufacturerLookupDto>(fined));
            }
Пример #6
0
            public async Task <GoodDto> Handle(CreateGoodCommand request, CancellationToken cancellationToken)
            {
                var result = await _context.Good.AddAsync(new Good
                {
                    GoodName       = request.GoodName,
                    ManufacturerId = request.Manufacturer.ManufacturerId,
                    CategoryId     = request.Category.CategoryId,
                    Price          = request.Price,
                    GoodCount      = request.GoodCount
                }, cancellationToken);

                await _context.SaveChangesAsync(cancellationToken);

                return(_mapper.Map <GoodDto>(result.Entity));
            }
Пример #7
0
            public async Task <GoodDto> Handle(UpdateGoodCommand request, CancellationToken cancellationToken)
            {
                var fined = await _context.Good
                            .Where(good => good.GoodId == request.GoodId)
                            .FirstOrDefaultAsync(cancellationToken);

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

                fined.Category = await _context.Category
                                 .Where(category => category.CategoryId == request.Category.CategoryId)
                                 .FirstOrDefaultAsync(cancellationToken);

                fined.GoodName  = request.GoodName;
                fined.Price     = request.Price;
                fined.GoodCount = request.GoodCount;
                await _context.SaveChangesAsync(cancellationToken);

                return(_mapper.Map <GoodDto>(fined));
            }