Ejemplo n.º 1
0
        public async Task <BasketRepositoryModel> UpdateBasketAsync(BasketRepositoryModel basket)
        {
            var created = await this.database.StringSetAsync(basket.Id.ToString(), JsonConvert.SerializeObject(basket));

            if (!created)
            {
                throw new Exception("Could not create the basket");
            }

            return(await GetBasketAsync(basket.Id.Value));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostCheckOutAsync()
        {
            var userName = "******";

            Cart = _basketRepository.GetAllBasket();

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Order.UserName   = userName;
            Order.TotalPrice = Cart.TotalPrice;

            await _basketApi.CheckoutBasket(Order);

            return(RedirectToPage("Confirmation", "OrderSubmitted"));
        }
Ejemplo n.º 3
0
        public async Task <BasketServiceModel> UpdateAsync(UpdateBasketServiceModel serviceModel)
        {
            var basketModel = new BasketRepositoryModel
            {
                Id    = serviceModel.Id,
                Items = serviceModel.Items.OrEmptyIfNull().Select(x => new BasketItemRepositoryModel
                {
                    ProductId         = x.ProductId,
                    ProductSku        = x.ProductSku,
                    ProductName       = x.ProductName,
                    PictureUrl        = x.PictureUrl,
                    Quantity          = x.Quantity,
                    ExternalReference = x.ExternalReference,
                    DeliveryFrom      = x.DeliveryFrom,
                    DeliveryTo        = x.DeliveryTo,
                    MoreInfo          = x.MoreInfo
                })
            };

            var result = await this.basketRepository.UpdateBasketAsync(basketModel);

            return(new BasketServiceModel
            {
                Id = result.Id,
                Items = result.Items.OrEmptyIfNull().Select(x => new BasketItemServiceModel
                {
                    ProductId = x.ProductId,
                    ProductSku = x.ProductSku,
                    ProductName = x.ProductName,
                    PictureUrl = x.PictureUrl,
                    Quantity = x.Quantity,
                    ExternalReference = x.ExternalReference,
                    DeliveryFrom = x.DeliveryFrom,
                    DeliveryTo = x.DeliveryTo,
                    MoreInfo = x.MoreInfo
                })
            });
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync()
        {
            Cart = _basketRepository.GetAllBasket();

            return(Page());
        }
Ejemplo n.º 5
0
 public void Update(BasketRepositoryModel basketRepositoryModel)
 {
     _httpContextAccessor.HttpContext.Session.SetObject("basket", basketRepositoryModel);
 }