Пример #1
0
        private async Task HandlePublish(ProductDto product)
        {
            Guid id = Guid.Empty;

            if (product.IsPublished)
            {
                id = await ProductAppService.UnPublishAsync(product.Id);
            }
            else
            {
                id = await ProductAppService.PublishAsync(product.Id);
            }

            if (id != Guid.Empty)
            {
                var message = !product.IsPublished ? "Published " : "UnPublished";
                await Message.Success($"Product successfully {message}");
            }
            else
            {
                var message = product.IsPublished ? "Published " : "UnPublished";
                await Message.Error("Failed to " + message);
            }
            await InvokeAsync(StateHasChanged);
            await GetProductsAsync();
        }
    public virtual async Task HandleEventAsync(CreateFlashSaleOrderCompleteEto eventData)
    {
        if (eventData.Success)
        {
            return;
        }

        if (eventData.Reason != FlashSaleResultFailedReason.InvalidHashToken)
        {
            return;
        }

        var plan = await FlashSalePlanRepository.GetAsync(eventData.PlanId);

        var product = await ProductAppService.GetAsync(plan.ProductId);

        if (!await FlashSaleInventoryManager.TryRollBackInventoryAsync(
                plan.TenantId, product.InventoryProviderName,
                plan.StoreId, plan.ProductId, plan.ProductSkuId, 1, true
                ))
        {
            Logger.LogWarning("Try roll back inventory failed.");
            return;
        }

        await RemoveUserFlashSaleResultCacheAsync(plan, eventData.UserId);
    }
Пример #3
0
    public override async Task <FlashSalePlanDto> UpdateAsync(Guid id, FlashSalePlanUpdateDto input)
    {
        var flashSalePlan = await GetEntityByIdAsync(id);

        var product = await ProductAppService.GetAsync(input.ProductId);

        var productSku = product.GetSkuById(input.ProductSkuId);

        await CheckMultiStorePolicyAsync(product.StoreId, UpdatePolicyName);

        await ValidateProductAsync(input.ProductId, product, flashSalePlan.StoreId);

        if (await ExistRelatedFlashSaleResultsAsync(id) && (input.ProductId != flashSalePlan.ProductId || input.ProductSkuId != flashSalePlan.ProductSkuId))
        {
            throw new RelatedFlashSaleResultsExistException(id);
        }

        flashSalePlan.SetTimeRange(input.BeginTime, input.EndTime);
        flashSalePlan.SetProductSku(flashSalePlan.StoreId, product.Id, productSku.Id);
        flashSalePlan.SetPublished(input.IsPublished);

        flashSalePlan.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp);

        await FlashSalePlanRepository.UpdateAsync(flashSalePlan, autoSave : true);

        return(await MapToGetOutputDtoAsync(flashSalePlan));
    }
Пример #4
0
    public override async Task <FlashSalePlanDto> CreateAsync(FlashSalePlanCreateDto input)
    {
        await CheckMultiStorePolicyAsync(input.StoreId, CreatePolicyName);

        var product = await ProductAppService.GetAsync(input.ProductId);

        var productSku = product.GetSkuById(input.ProductSkuId);

        await ValidateProductAsync(input.ProductId, product, input.StoreId);

        var flashSalePlan = new FlashSalePlan(
            GuidGenerator.Create(),
            CurrentTenant.Id,
            input.StoreId,
            input.BeginTime,
            input.EndTime,
            product.Id,
            productSku.Id,
            input.IsPublished
            );

        await FlashSalePlanRepository.InsertAsync(flashSalePlan, autoSave : true);

        return(await MapToGetOutputDtoAsync(flashSalePlan));
    }
Пример #5
0
 public OrderAppService(IRepository <Order> orderRepository, IMapper mapper, ProductAppService productAppService, IRepository <OrderItem> orderItemRepository, IUnitOfWorkManager unitOfWorkManager)
 {
     this.orderRepository     = orderRepository;
     this.mapper              = mapper;
     this.productAppService   = productAppService;
     this.orderItemRepository = orderItemRepository;
     this.unitOfWorkManager   = unitOfWorkManager;
 }
Пример #6
0
        private async Task DeleteProductAsync(ProductDto product)
        {
            var confirmMessage = L["ProductDeletionConfirmationMessage", product.Title];

            if (!await Message.Confirm(confirmMessage))
            {
                return;
            }

            await ProductAppService.DeleteAsync(product.Id);

            await GetProductsAsync();
        }
Пример #7
0
        private async Task GetProductsAsync()
        {
            var result = await ProductAppService.GetListAsync(
                new PagedProductRequestDto
            {
                MaxResultCount = PageSize,
                SkipCount      = CurrentPage * PageSize,
                Sorting        = CurrentSorting
            }
                );

            ProductList = result.Items;
            TotalCount  = (int)result.TotalCount;
        }
        public void Create_NullParamater_ThrowsException()
        {
            var mockRepo = new Mock <IRepository <Product> >();

            mockRepo.Setup(x => x.Insert(It.IsAny <Product>())).Returns(new Product());
            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(x => x.Commit()).Returns(1);
            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <Product, ProductDetailsOutput>(It.IsAny <Product>())).Returns(new ProductDetailsOutput());

            var productService = new ProductAppService(mockUow.Object, mockRepo.Object, mockMapper.Object);

            productService.Create(null);
        }
Пример #9
0
    public virtual async Task <FlashSalePlanPreOrderDto> PreOrderAsync(Guid id)
    {
        var plan = await GetFlashSalePlanCacheAsync(id);

        var product = await ProductAppService.GetAsync(plan.ProductId);

        var productSku  = product.GetSkuById(plan.ProductSkuId);
        var expiresTime = DateTimeOffset.Now.Add(Options.PreOrderExpires);

        await ValidatePreOrderAsync(plan, product, productSku);

        await SetPreOrderCacheAsync(plan, product, productSku, expiresTime);

        return(new FlashSalePlanPreOrderDto {
            ExpiresTime = Clock.Normalize(expiresTime.LocalDateTime), ExpiresInSeconds = Options.PreOrderExpires.TotalSeconds
        });
    }
    public virtual async Task HandleEventAsync(CreateFlashSaleOrderEto eventData)
    {
        var product = await ProductAppService.GetAsync(eventData.Plan.ProductId);

        var productSku = product.GetSkuById(eventData.Plan.ProductSkuId);

        if (!await ValidateHashTokenAsync(eventData.Plan, product, productSku, eventData.HashToken))
        {
            await DistributedEventBus.PublishAsync(new CreateFlashSaleOrderCompleteEto()
            {
                TenantId        = eventData.TenantId,
                PlanId          = eventData.PlanId,
                OrderId         = null,
                UserId          = eventData.UserId,
                StoreId         = eventData.StoreId,
                PendingResultId = eventData.PendingResultId,
                Success         = false,
                Reason          = FlashSaleResultFailedReason.InvalidHashToken
            });

            return;
        }

        var input = await ConvertToCreateOrderDtoAsync(eventData);

        var productDict = await GetProductDictionaryAsync(product);

        var productDetailDict = await GetProductDetailDictionaryAsync(product, productSku);

        var order = await NewOrderGenerator.GenerateAsync(eventData.UserId, input, productDict, productDetailDict);

        await OrderRepository.InsertAsync(order, autoSave : true);

        await DistributedEventBus.PublishAsync(new CreateFlashSaleOrderCompleteEto()
        {
            TenantId        = eventData.TenantId,
            PlanId          = eventData.PlanId,
            OrderId         = order.Id,
            UserId          = eventData.UserId,
            StoreId         = eventData.StoreId,
            PendingResultId = eventData.PendingResultId,
            Success         = true,
            Reason          = null
        });
    }
        public void Create_ValidParamater_ReturnsNewInstance()
        {
            var mockRepo = new Mock <IRepository <Product> >();

            mockRepo.Setup(x => x.Insert(It.IsAny <Product>())).Returns(new Product());
            var mockUow = new Mock <IUnitOfWork>();

            mockUow.Setup(x => x.Commit()).Returns(1);
            var mockMapper = new Mock <IMapper>();

            mockMapper.Setup(x => x.Map <Product, ProductDetailsOutput>(It.IsAny <Product>())).Returns(new ProductDetailsOutput());
            var productService = new ProductAppService(mockUow.Object, mockRepo.Object, mockMapper.Object);

            var result = productService.Create(new ProductCreateInput());

            mockRepo.Verify(x => x.Insert(It.IsAny <Product>()));
            mockUow.Verify(x => x.Commit());
            Assert.IsNotNull(result);
        }
Пример #12
0
        public ProductControllerTest()
        {
            this.fixture = new Fixture();
            this.productAppServiceMock = new Mock <IProductAppService>();
            this.productServiceMock    = new Mock <IProductService>();
            this.productRepositoryMock = new Mock <IProductRepository>();

            var options = new DbContextOptionsBuilder <ProductContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            this.productContextMock = new ProductContext(options);
            this.productContextMock.Database.EnsureCreated();


            //auto mapper configuration
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperConfig());
                cfg.AddProfile(new Infra.Data.AutoMapper.AutoMapperConfig());
            });

            var mapper = mockMapper.CreateMapper();

            this.productController = new ProductController(
                this.productAppServiceMock.Object);

            this.productAppService = new ProductAppService(
                this.productServiceMock.Object, mapper);

            this.productService = new ProductService(
                this.productRepositoryMock.Object);

            this.productRepository = new ProductRepository(
                this.productContextMock, mapper);
        }
 public ProductsController(ProductAppService productAppService)
 {
     _productAppService = productAppService;
 }
Пример #14
0
 public void Initial()
 {
     productAppService = new ProductAppService();
 }
Пример #15
0
 public ProductTest()
 {
     _service = new ProductAppService(_mockRepository.Object, _mockProductRepository.Object);
 }
 //REALIZAR A INJEÇÃO DE DEPENDÊCIA
 public ClientProductController(ClientProductAppService clientProductAppService, ClientAppService clientAppService, ProductAppService productAppService)
 {
     _clientProductAppService = clientProductAppService;
     _clientAppService        = clientAppService;
     _productAppService       = productAppService;
 }
Пример #17
0
 public HomeController(ProductAppService productAppService)
 {
     _productAppService = productAppService;
 }