Exemplo n.º 1
0
        //Валидация представления элемента корзины
        //Число заказанных товаров не должно быть <= 0 и больше фактического
        public bool BasketItemIsValid(BasketItemView basketItemView)
        {
            BookVariableInfo bookVariableInfo;

            bookVariableInfo = (BookVariableInfo)
                this._bookVariableInfoRepository.FindById(
                basketItemView.BookVariableInfoId);
            if (basketItemView.ItemCount > bookVariableInfo.ProductCount ||
                basketItemView.ItemCount <= 0)
                return false;

            return true;
        }
Exemplo n.º 2
0
        //Извлечение BasketItem из BasketItemView
        public BasketItem GetBasketItem(BasketItemView basketItemView)
        {
            BasketItem basketItem;
            BasketRepository basketRepository;
            BookVariableInfoRepository bookVariableInfoRepository;
            PaymentRepository paymentRepository;

            basketItem = new BasketItem()
            {
                Id = basketItemView.Id,
                Amount = basketItemView.Amount,
                BasketId = basketItemView.BasketId,
                BookVariableInfoId = basketItemView.BookVariableInfoId,
                ItemCount = basketItemView.ItemCount,
                PaymentId = basketItemView.PaymentId
            };

            basketItem.BookVariableInfo = (BookVariableInfo)
                this._bookVariableInfoRepository.FindById(
                basketItem.BookVariableInfoId);
            if (basketItem.BasketId != null)
                basketItem.Basket = (Basket)
                    this._basketRepository.FindById((Int32)basketItem.BasketId);
            if (basketItem.PaymentId != null)
                basketItem.Payment = (Payment)
                    this._paymentRepository.FindById((Int32)basketItem.PaymentId);

            return basketItem;
        }
Exemplo n.º 3
0
        public ActionResult BuyBook(Int32 bookId)
        {
            BookVariableInfo bookVariableInfo;
            BookVariableInfoRepository bookVariableInfoRepository;
            BasketItemView basketItemView;
            BasketService basketService;
            Basket basket;

            if (User.Identity.IsAuthenticated)
            {
                bookVariableInfoRepository = (BookVariableInfoRepository)
                    this._bookVariableInfoRepository;
                basketService = new BasketService();

                bookVariableInfo = bookVariableInfoRepository.FindByBookId(bookId);
                basket = basketService.GetBasket(User.Identity.Name);
                basketItemView = new BasketItemView(
                    new BasketItem()
                {
                    BookVariableInfo = bookVariableInfo,
                    BookVariableInfoId = bookVariableInfo.Id,
                    Basket = basket,
                    BasketId = basket.Id
                });
            }
            else return Content("Сначала авторизуйтейсь.");

            return View(basketItemView);
        }
Exemplo n.º 4
0
        public ActionResult BuyBook(BasketItemView basketItemView)
        {
            bool isOk = true;
            BasketService basketService;
            Basket basket;
            BasketItem basketItem;
            UserProfile userProfile;
            Individual individual;

            if (basketItemView.BookVariableInfo == null)
                basketItemView.BookVariableInfo = (BookVariableInfo)
                    this._bookVariableInfoRepository
                    .FindById(basketItemView.BookVariableInfoId);
            if (ModelState.IsValid)
            {
                basketService = new BasketService();
                if (basketService.BasketItemIsValid(basketItemView))
                {
                    basketService = new BasketService();
                    //Извлечение BasketItem из BasketItemView
                    basketItem = basketService.GetBasketItem(
                        basketItemView);

                    basket = basketService.GetBasket(User.Identity.Name);
                    if (basketService.AddBookItem(basket, basketItem))
                        return RedirectToAction("Index");
                    else isOk = false;
                }
                else isOk = false;

                if (!isOk)
                    return Content(
                    "Укажите суммарное число экземпляров > 0 и <= общего числа.");
            }

            return View(basketItemView);
        }
Exemplo n.º 5
0
        public ActionResult UpdateBasketItem(Int32 basketItemId)
        {
            BasketItem basketItem;
            BasketItemView basketItemView;

            basketItem = (BasketItem)this._basketItemRepository
                .FindById(basketItemId);
            basketItemView = new BasketItemView(basketItem);

            return View(basketItemView);
        }