Exemplo n.º 1
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.º 2
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.º 3
0
        public ActionResult ViewShops(IList<ShopView> shopViews)
        {
            CityRepository cityRepository;
            Basket basket;
            BasketService basketService;
            IList<Shop> shops;

            basketService = new BasketService();
            basket = basketService.GetBasket(User.Identity.Name);
            if (basket.BasketItems.Count > 0)
            {
                cityRepository = (CityRepository)this._cityRepository;
                ViewData["cityNames"] =
                    cityRepository.GetSelectItemList(
                        this._cityRepository.GetAll().cities);
            }
            else return Content("Сперва, сделайте заказ");

            if (shopViews == null)
            {
                shops = this._shopRepository.GetAll().shops;
                shopViews = (from shop in shops
                             select new ShopView(shop))
                             .ToList<ShopView>();
            }

            return View(shopViews);
        }
Exemplo n.º 4
0
        public ActionResult SelectShop(Shop shop)
        {
            Basket basket;
            IList<Shop> shops;
            PaymentView paymentView;
            UrlGenerator urlGenerator;
            Payment payment, dbPayment;
            W1Payment w1Payment, dbW1Payment;
            W1PaymentView w1PaymentView;
            Individual individual;
            BasketService basketService;
            IndividualRepository individualRepository;
            PaymentRepository paymentRepository;
            PaymentService paymentService;

            //Необходимо вызвать UrlGenerator в любом Post-методе контроллера,
            //иначе Request и Url поля не будут доступны.
            //В будующем нужно исправить!
            urlGenerator = new UrlGenerator(this.Request, this.Url);

            basketService = new BasketService();
            paymentRepository = new PaymentRepository();
            paymentService = new PaymentService();
            individualRepository = new IndividualRepository();
            //----
            shop = (Shop)this._shopRepository.FindById(shop.Id); //для адреса

            basket = basketService.GetBasket(User.Identity.Name);

            //Вычитаем заказанныек книги из BookVariableInfo и
            //обвновляем Basket
            basketService.ShopProcessing(basket, shop);
            shop.Address = (Address)this._addressRepository.FindById(shop.Id);
            //--
            //Создание платежной формы W1Payment
            individual = (Individual)individualRepository
                .FindIndividualByUserProfileName(User.Identity.Name);

            w1Payment = new W1Payment();
            w1Payment.WMI_PAYMENT_AMOUNT = paymentService.DecimalCounting(
                basket.TotalAmount, shop.BookDeliveryCost);
            w1Payment.WMI_DESCRIPTION = paymentService.MakeDescription(basket.Id);
            dbW1Payment = paymentService.MakeW1Payment(w1Payment);
            //добавление payment и w1Payment
            payment = new Payment()
            {
                Id = dbW1Payment.WMI_PAYMENT_NO,
                ShopId = shop.Id,
                IndividualId = individual.Id
            };
            dbPayment = paymentService.AddPayment(payment, w1Payment);
            payment.Id = dbPayment.Id;

            //Перемещение заказов из корзины в платеж и очистка корзины
            basketService.BasketToPaymentMigration(basket, payment);

            //-Создали представление для отображения w1Payment и передачи его в POST
            w1PaymentView = new W1PaymentView(dbW1Payment);//payment, basket);

            return RedirectToAction("BasketPay", w1PaymentView);//shop); //payment);
        }
Exemplo n.º 5
0
        public ActionResult Index()
        {
            BasketView basketView;
            BasketService basketService;

            if (User.Identity.IsAuthenticated)
            {
                basketService = new BasketService();
                basketView = new BasketView(
                    basketService.GetBasket(User.Identity.Name));
            }
            else return Content("Сначала авторизуйтейсь.");

            return View(basketView);
        }
Exemplo n.º 6
0
        public ActionResult DeleteBasketItem(Int32 basketItemId)
        {
            BasketItem basketItem;
            BasketService basketService;

            basketItem = (BasketItem)this._basketItemRepository
                .FindById(basketItemId);

            basketService = new BasketService();
            basketService.DeleteBasketItem(basketItem);

            return RedirectToAction("Index");
        }