Exemplo n.º 1
0
        public async Task <SpecialOfferViewModel> GetValidShopOfferAsync(CancellationToken ct = default)
        {
            // retrieve all special offers
            List <SpecialOffer> specialOffers = await this._specialOfferRepository.GetAllAsync(ct);

            List <SpecialOffer> shopOffers = specialOffers.Where(o => o.Scope == OfferScope.Shop && o.ExpireDate > DateTime.Now).ToList();

            SpecialOfferViewModel shopOffer = null;

            // if the count is greater than 1 then we have a problem, we only ever want to display one shop offer
            if (shopOffers.Count == 1)
            {
                shopOffer = SpecialOfferConverter.Convert(shopOffers.First());

                // check if shop offer is a promo code
                if (shopOffer.Type == OfferType.PromoCode)
                {
                    if (String.IsNullOrEmpty(shopOffer.PromoCodeId) == false)
                    {
                        PromoCodeViewModel promoViewModel = PromoCodeConverter.Convert(await this._promoCodeRepository.GetByIdAsync(shopOffer.PromoCodeId, ct));
                        // check if promo is valid
                        if (promoViewModel.ExpireDate > DateTime.Now)
                        {
                            shopOffer.PromoCode = promoViewModel;
                        }
                    }
                }
            }

            return(shopOffer);
        }
Exemplo n.º 2
0
        private async Task <CustomProductViewModel> GetCustomSackProdctAsync(CancellationToken ct = default)
        {
            CustomProduct customSack = await this._customProductRepository.GetCustomSackAsync(ct);

            List <MixCategory> mixCategories = await this._mixCategoryRepository.GetAllByProductIdAsync(customSack.Id);

            foreach (MixCategory category in mixCategories)
            {
                category.Ingredients = await this._ingredientRepository.GetAllByMixCategoryIdAsync(category.Id, ct);
            }

            customSack.MixCategories = mixCategories;

            CustomProductViewModel customSackView = CustomProductConverter.Convert(customSack);

            if (customSackView.IsOnSale == true)
            {
                List <SaleItem> sales = await this._saleItemRepository.GetByCustomProductId(customSack.Id);

                List <SaleItemViewModel> saleViews = new List <SaleItemViewModel>();
                foreach (SaleItem sale in sales)
                {
                    SaleItemViewModel saleView = SaleItemConverter.Convert(sale);
                    // if sale item is a promo code
                    if (sale.Type == OfferType.PromoCode)
                    {
                        // ensure promo code id exists on
                        if (String.IsNullOrEmpty(sale.PromoCodeId) == false)
                        {
                            PromoCodeViewModel promoViewModel = PromoCodeConverter.Convert(await this._promoCodeRepository.GetByIdAsync(sale.PromoCodeId, ct));
                            // check if promo is valid
                            if (promoViewModel.ExpireDate > DateTime.Now)
                            {
                                saleView.PromoCode = promoViewModel;
                                saleViews.Add(saleView);
                            }
                        }
                    }
                    else
                    {
                        // if sale is valid
                        if (sale.ExpireDate > DateTime.Now)
                        {
                            saleViews.Add(saleView);
                        }
                    }
                }
                customSackView.Sales = saleViews;
            }

            return(customSackView);
        }