// GET: Sages/Create
        public async Task <ActionResult> Create()
        {
            var sageViewModel = new SageViewModel();

            var books = await _bookApiService.GetAsync();

            sageViewModel.AllBooks = books
                                     .Select(x => new SelectListItem
            {
                Value = x.IdBook.ToString(),
                Text  = x.Name
            })
                                     .ToList();

            return(View(sageViewModel));
        }
Esempio n. 2
0
        public async Task <ActionResult> Buy(int id)
        {
            var book = await _bookApiService.GetAsync(id);

            if (Session["basket"] == null)
            {
                var basket = new List <BookOrder>();

                basket.Add(new BookOrder {
                    BookId = id, Book = book, Quantity = 1
                });

                Session["basket"] = basket;
            }
            else
            {
                var basket = (List <BookOrder>)Session["basket"];

                var index = IsExist(id);

                if (index != -1)
                {
                    basket[index].Quantity++;
                }
                else
                {
                    basket.Add(new BookOrder {
                        BookId = id, Book = book, Quantity = 1
                    });
                }

                Session["basket"] = basket;
            }

            return(RedirectToAction("Index", "Books"));
        }
Esempio n. 3
0
        // GET: Books
        public async Task <ActionResult> Index()
        {
            var books = await _bookApiService.GetAsync();

            return(View(books));
        }