Exemplo n.º 1
0
        public CartItem AddToCart(JsonElement request)
        {
            var     productId  = request.GetProperty("productId").GetString();
            var     categoryId = request.GetProperty("categoryId").GetString();
            Product product;

            product = _giftRepository.GetGift(int.Parse(productId));

            var user = GetCurrentUserAsync().Result;
            var cart = _cartRepository.GetAllCarts().LastOrDefault(c => c.CustomerId == user.Id && c.isOrdered == false) ?? new Cart();

            cart.Customer   = user;
            cart.CustomerId = user.Id;
            var cartItem = _cartItemRepository.GetAllCartItems()
                           .FirstOrDefault(c => c.ProductId == product.Id && c.CartId == cart.Id) ?? new CartItem();

            cartItem.Product = product;
            cartItem.Cart    = cart;
            cartItem.Quantity++;
            cartItem.CartId    = cart.Id;
            cartItem.ProductId = product.Id;
            _cartItemRepository.AddOrUpdate(cartItem);
            _cartRepository.AddOrUpdate(cart);

            return(cartItem);
        }
Exemplo n.º 2
0
        public void ReserveGift(string guestName, string guestEmail, int giftId, int quantityReserved)
        {
            _loggingService.LogInformation(string.Format("Guest {0}({1}) is reserving {2} of gift {3}", guestName, guestEmail, giftId, quantityReserved));
            Guest guest = new Guest {
                Email = guestEmail, Name = guestName, CreatedDate = DateTime.Now
            };
            var giftPurchase = new GiftPruchase(giftId, quantityReserved);

            _userRepository.InserstGuestGiftReservation(guest, giftPurchase);
            Gift gift = _giftRepository.GetGift(giftId);

            gift.PendingReservation = true;
            _giftRepository.UpdateGift(gift);
            _mailService.SendPurchaseConfirmationEmail(guest, giftPurchase, gift);
        }
Exemplo n.º 3
0
        public IActionResult GetGift(int giftNumber)
        {
            var gift = _giftRepository.GetGift(giftNumber);

            if (gift == null)
            {
                return(NotFound());
            }

            return(Ok(gift));
        }
        public async Task <IHttpActionResult> Get(IdModel id)
        {
            if (id == null)
            {
                return(ErrorApiResult(300, "Не передан id.Либо левый формат"));
            }
            var result = await _giftRepository.GetGift((long)id.Id);

            if (result == null)
            {
                return(ErrorApiResult(300, "Не найден"));
            }
            return(SuccessApiResult(result));
        }
Exemplo n.º 5
0
        public IActionResult OrderDetails(int id)
        {
            var order     = _orderRepository.GetOrder(id);
            var cartItems = _cartItemRepository.GetAllCartItems().Where(c => c.CartId == order.CartId);
            var total     = 0.0;

            foreach (var cartItem in cartItems)
            {
                var product = _giftRepository.GetGift(cartItem.ProductId);
                cartItem.Product = product;
                total           += product.Price;
            }

            order.Customer   = _userManager.FindByIdAsync(order.CustomerId).Result;
            ViewBag.Order    = order;
            ViewBag.Products = cartItems;
            ViewBag.Total    = total;
            return(order == null?View("NotFound") : View());
        }
Exemplo n.º 6
0
 public IActionResult GiftDetails(int id)
 {
     ViewBag.Gift = _giftRepository.GetGift(id);
     return(View());
 }