public async Task <Unit> Handle(CreateMerchantProductCommand request, CancellationToken cancellationToken)
        {
            var product = await _productRepository.GetWithSkuAsync(request.Sku);

            if (product == null)
            {
                throw new ProductNotFoundException("Product Not Found");
            }
            var merchantAddress = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            if (merchantAddress is null)
            {
                throw new MerchantAddressNotFoundException();
            }

            var newMerchantProduct = Domain.Merchant.MerchantProduct.AddCreated(request.MerchantCode,
                                                                                product.Name,
                                                                                product.Sku,
                                                                                product.Barcode,
                                                                                request.Price,
                                                                                request.Vat,
                                                                                request.PriceWithVat,
                                                                                request.IsActive,
                                                                                product.Description,
                                                                                request.Stock,
                                                                                request.IsInfiniteStock,
                                                                                request.MerchantAddressCode,
                                                                                product.Images,
                                                                                product.Tags);

            await _merchantProductRepository.CreateAsync(newMerchantProduct);

            return(Unit.Task.Result);
        }
Ejemplo n.º 2
0
        public async Task <Unit> Handle(UpdateMerchantProductCommand request, CancellationToken cancellationToken)
        {
            var product = await _productRepository.GetWithSkuAsync(request.Sku);

            if (product is null)
            {
                throw new ProductNotFoundException();
            }
            var merchantAddress = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            if (merchantAddress is null)
            {
                throw new MerchantAddressNotFoundException();
            }

            await _merchantProductRepository.UpdateAsync(request.Sku, request.MerchantCode, request.MerchantAddressCode,
                                                         new Domain.Merchant.MerchantProduct
            {
                IsActive            = request.IsActive,
                IsInfiniteStock     = request.IsInfiniteStock,
                Stock               = request.Stock,
                MerchantAddressCode = merchantAddress.Code,
                Price               = request.Price,
                Vat              = request.Vat,
                PriceWithVat     = request.PriceWithVat,
                ProductImageUrls = product.Images,
                ProductTags      = product.Tags,
                Name             = request.ProductName
            });

            return(Unit.Task.Result);
        }
Ejemplo n.º 3
0
        public async Task <MerchantAddressDto> Handle(GetMerchantAddressQuery request, CancellationToken cancellationToken)
        {
            var address = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            if (address is null)
            {
                throw new MerchantAddressNotFoundException("Merchant Address Not Found");
            }
            var addressDto = new MerchantAddressDto
            {
                Code         = address.Code,
                MerchantName = address.MerchantName,
                Name         = address.Name,
                Address      = address.Address,
                Country      = address.Country,
                State        = address.State,
                City         = address.City,
                Town         = address.Town,
                District     = address.District,
                Location     = address.Location,
                ExtraInfo    = address.ExtraInfo,
                WorkingHours = address.WorkingHours,
                IsActive     = address.IsActive
            };

            return(addressDto);
        }
        public async Task <MerchantAddressDto> Handle(AddMerchantAddressCommand request, CancellationToken cancellationToken)
        {
            var merchant = await _merchantRepository.GetAsync(request.MerchantCode);

            if (merchant is null)
            {
                throw new MerchantNotFoundException();
            }

            var merchantLocation = MerchantAddress.RegisterCreated(
                request.MerchantCode,
                request.MerchantName,
                request.Name,
                request.Address,
                request.Country,
                request.City,
                request.Town,
                request.District,
                request.Location,
                request.WorkingHours,
                request.ExtraInfo);

            merchantLocation.Activate();
            var locations = await _merchantLocationsRepository.GetAsync(request.MerchantCode, request.Name);

            if (locations != null)
            {
                throw new MerchantAddressAlreadyRegisteredException();
            }

            await _merchantLocationsRepository.AddAsync(merchantLocation);

            return(_mapper.Map <MerchantAddressDto>(merchantLocation));
        }
Ejemplo n.º 5
0
        public async Task <Unit> Handle(CreateOrderCommand request, CancellationToken cancellationToken)
        {
            if (request.OrderProducts is null || !request.OrderProducts.Any())
            {
                throw new ProductNotFoundException();
            }
            if (request.OrderProducts.Any(x => x.Quantity < 1))
            {
                throw new ProductItemShouldHaveAtLeastOneQuantityException();
            }

            var merchant = await _merchantRepository.GetAsync(request.MerchantCode);

            var merchantAddress = await _merchantLocationsRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            var address = new Address
            {
                Code        = merchantAddress.Code,
                FullAddress = merchantAddress.Location,
                City        = merchantAddress.City,
                Town        = merchantAddress.Town,
                District    = merchantAddress.District,
                Name        = merchantAddress.Name,
            };

            var order = Order.Create(merchant.Name, merchant.Code, request.FirstName, request.LastName, request.Phone,
                                     request.OrderNote, address, request.ReceiverAddress, request.OrderProducts);
            await _orderRepository.CreateAsync(order);

            return(Unit.Task.Result);
        }
Ejemplo n.º 6
0
        public async Task <Unit> Handle(DeactivateAvailableLocationCommand request, CancellationToken cancellationToken)
        {
            var merchantLocation = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            merchantLocation = merchantLocation.DeactiveAvailableLocations(request.Locations);
            await _merchantAddressRepository.UpdateAsync(merchantLocation);

            return(Unit.Task.Result);
        }
Ejemplo n.º 7
0
        public async Task <bool> IsUnique(Guid merchantCode, Guid merchantAddressCode, List <Location> locations)
        {
            var availableLocation = await _merchantAddressRepository.GetAsync(merchantCode, merchantAddressCode);

            foreach (var location in availableLocation.AvailableLocations)
            {
                if (locations.Any(x => x.Equals(location)))
                {
                    return(false);
                }
            }
            return(true);
        }
        public async Task <Unit> Handle(ActivateMerchantAddressCommand request, CancellationToken cancellationToken)
        {
            var merchantAddress = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            if (merchantAddress is null)
            {
                throw new MerchantAddressNotFoundException();
            }

            merchantAddress.Activate();
            await _merchantAddressRepository.UpdateIsActiveAsync(merchantAddress.MerchantName, merchantAddress.Name, merchantAddress.IsActive);

            await _merchantRepository.AddAddressMetaDataAsync(merchantAddress.MerchantName, merchantAddress.Name);

            return(Unit.Task.Result);
        }
        public async Task <MerchantAddressDto> Handle(UpdateMerchantAddressCommand request, CancellationToken cancellationToken)
        {
            var merchant = await _merchantRepository.GetAsync(request.MerchantCode);

            if (merchant is null)
            {
                throw new MerchantNotFoundException();
            }

            var merchantLocation = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            if (merchantLocation is null)
            {
                throw new ActiveMerchantLocationNotFoundException();
            }

            merchantLocation.Update(request.Name, request.Address, request.City, request.Town, request.District,
                                    request.Location, request.WorkingHours, request.ExtraInfo);
            await _merchantAddressRepository.UpdateAsync(merchantLocation);

            return(_mapper.Map <MerchantAddressDto>(merchantLocation));
        }
        public async Task <Unit> Handle(CreateBulkMerchantProductCommand request, CancellationToken cancellationToken)
        {
            var merchantProductList = new List <Domain.Merchant.MerchantProduct>();

            foreach (var item in request.CreateMerchantProductList)
            {
                var product = await _productRepository.GetWithSkuAsync(item.Sku);

                if (product is null)
                {
                    continue;
                }
                var merchantAddress = await _merchantAddressRepository.GetAsync(request.MerchantCode, item.MerchantAddressCode);

                if (merchantAddress is null)
                {
                    throw new MerchantAddressNotFoundException();
                }
                var newMerchantProduct = Domain.Merchant.MerchantProduct.AddCreated(request.MerchantCode,
                                                                                    product.Name,
                                                                                    product.Sku,
                                                                                    product.Barcode,
                                                                                    item.Price,
                                                                                    item.Vat,
                                                                                    item.PriceWithVat,
                                                                                    item.IsActive,
                                                                                    product.Description,
                                                                                    item.Stock,
                                                                                    item.IsInfiniteStock,
                                                                                    merchantAddress.Code,
                                                                                    product.Images,
                                                                                    product.Tags);
                merchantProductList.Add(newMerchantProduct);
            }
            await _merchantProductRepository.BulkCreateAsync(merchantProductList);

            return(Unit.Task.Result);
        }
        public async Task <BaseListResponseModel <Location> > Handle(GetAvailableLocationsQuery request, CancellationToken cancellationToken)
        {
            var merchantAddress = await _merchantAddressRepository.GetAsync(request.MerchantCode, request.MerchantAddressCode);

            return(new BaseListResponseModel <Location>(request.Limit, merchantAddress.AvailableLocations));
        }