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);
    }
Ejemplo n.º 2
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));
    }
Ejemplo n.º 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));
    }
Ejemplo n.º 4
0
 protected virtual async Task <FlashSalePlanCacheItem> GetFlashSalePlanCacheAsync(Guid id)
 {
     return(await PlanDistributedCache.GetOrAddAsync(id, async() =>
     {
         var flashSalePlan = await FlashSalePlanRepository.GetAsync(id);
         return ObjectMapper.Map <FlashSalePlan, FlashSalePlanCacheItem>(flashSalePlan);
     }));
 }
Ejemplo n.º 5
0
    public override async Task DeleteAsync(Guid id)
    {
        var flashSalePlan = await GetEntityByIdAsync(id);

        await CheckMultiStorePolicyAsync(flashSalePlan.StoreId, DeletePolicyName);

        if (await ExistRelatedFlashSaleResultsAsync(id))
        {
            throw new RelatedFlashSaleResultsExistException(id);
        }

        await FlashSalePlanRepository.DeleteAsync(flashSalePlan);
    }