Ejemplo n.º 1
0
        public ActionResult Buy(Sale sale)
        {
            var model = new ConfirmBuyViewModel();

            sale.sale_date = DateTime.Now;

            try
            {
                using (var dbContext = new Bookshop_DBContext())
                {
                    var bk = dbContext.Books.First(book => book.book_id == sale.book_id);
                    sale.price = bk.price * sale.books_count;

                    model.BookName = bk.book_name;

                    if (bk.available_count < sale.books_count || sale.books_count < 1)
                    {
                        model.ErrorMessage = "Sorry, we haven't enough books. Please, try later.";
                        return(View("ConfirmBuy", model));
                    }
                }
            }
            catch (SqlException e)
            {
                model.ErrorMessage = e.Message;
                return(View("ConfirmBuy", model));
            }

            model.Sale         = sale;
            model.ErrorMessage = "";
            return(View("ConfirmBuy", model));
        }
Ejemplo n.º 2
0
        public IActionResult ConfirmBuy(Guid id)
        {
            var model = new ConfirmBuyViewModel
            {
                PropertyInfos = _propertyInfos.get(id)
            };

            return(View(model));
        }