Пример #1
0
        private CustomerBasket MapToCustomerBasket(CustomerBasketRequest customerBasketRequest)
        {
            var response = new CustomerBasket
            {
                BuyerId = customerBasketRequest.Buyerid,
                Coupon  = customerBasketRequest.Coupon == null ? new Coupon()
                {
                    Discount = 0
                } : new Coupon
                {
                    CouponCode     = customerBasketRequest.Coupon.Couponcode,
                    ExpirationDate = customerBasketRequest.Coupon.Expirationdate,
                    Discount       = (decimal)customerBasketRequest.Coupon.Discount
                }
            };

            customerBasketRequest.Items.ToList().ForEach(item => response.Items.Add(new BasketItem
            {
                Id           = item.Id,
                OldUnitPrice = (decimal)item.Oldunitprice,
                PictureUrl   = item.Pictureurl,
                ProductId    = item.Productid,
                ProductName  = item.Productname,
                Quantity     = item.Quantity,
                UnitPrice    = (decimal)item.Unitprice,
                isDiscounted = item.Isdiscounted
            }));

            return(response);
        }
Пример #2
0
        public override async Task <CustomerBasketResponse> UpdateBasket(CustomerBasketRequest request, ServerCallContext context)
        {
            _logger.LogInformation("Begin grpc call BasketService.UpdateBasketAsync for buyer id {Buyerid}", request.Buyerid);

            var customerBasket = MapToCustomerBasket(request);

            var response = await _repository.UpdateBasketAsync(customerBasket);

            if (response != null)
            {
                return(MapToCustomerBasketResponse(response));
            }

            context.Status = new Status(StatusCode.NotFound, $"Basket with buyer id {request.Buyerid} do not exist");

            return(null);
        }
Пример #3
0
        private CustomerBasket MapToCustomerBasket(CustomerBasketRequest customerBasketRequest)
        {
            var response = new CustomerBasket
            {
                BuyerId = customerBasketRequest.Buyerid
            };

            customerBasketRequest.Items.ToList().ForEach(item => response.Items.Add(new BasketItem
            {
                Id           = item.Id,
                OldUnitPrice = (decimal)item.Oldunitprice,
                PictureUrl   = item.Pictureurl,
                ProductId    = item.Productid,
                ProductName  = item.Productname,
                Quantity     = item.Quantity,
                UnitPrice    = (decimal)item.Unitprice
            }));

            return(response);
        }