Example #1
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));
    }
    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);
    }
Example #3
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));
    }
Example #4
0
        public async Task <IActionResult> Get(Guid productId)
        {
            var result = new Result <ProductDto>()
            {
                data = await _productAppService.GetAsync(productId)
            };

            return(Json(result));
        }
Example #5
0
        public async Task <IActionResult> Item(Guid?id)
        {
            if (id.HasValue)
            {
                var dto = await _productAppService.GetAsync(id.Value);

                return(View(dto));
            }
            return(View());
        }
Example #6
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
        });
    }