예제 #1
0
        // GET: Book/Create
        public async Task <ActionResult> CreateOrEdit(int id = 0)
        {
            Book book = new Book();

            if (id != 0)
            {
                book = await BookstoreClient.GetBookAsync(id) ?? book;
            }

            return(View(book));
        }
예제 #2
0
        // GET: Book/Delete/5
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                bool response = await BookstoreClient.DeleteBookAsync(id);

                if (response)
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(View());
                }
            }
            catch
            {
                return(View());
            }
        }
예제 #3
0
        public async Task <ActionResult> Create([Bind()] Book book)
        {
            try
            {
                Book response;

                if (book.Id == 0)
                {
                    response = await BookstoreClient.CreateAsync(book);
                }
                else
                {
                    response = await BookstoreClient.UpdateBookAsync(book);
                }

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
예제 #4
0
        public async Task <ActionResult> RegisterSell(StockMovement stockMovement)
        {
            await BookstoreClient.RegisterSellAsync(stockMovement);

            return(RedirectToAction(nameof(Index)));
        }
예제 #5
0
        public async Task <ActionResult> ChangePrice(ItemPrice itemPrice)
        {
            await BookstoreClient.ChangePriceAsync(itemPrice);

            return(RedirectToAction(nameof(Index)));
        }
예제 #6
0
        // GET: Book
        public async Task <ActionResult> Index()
        {
            var books = await BookstoreClient.GetBooksAsync();

            return(View(books));
        }
예제 #7
0
 public BookController(IConfiguration config)
 {
     BooksEndpoint   = config.GetValue <string>("Endpoints:Books");
     BookstoreClient = BookstoreClient.Build(BooksEndpoint);
 }