예제 #1
0
        public ActionResult Buy(BuyViewModel vm)
        {
            if (vm.Amount <= 0 || vm.Amount > vm.Limit || vm == null || !this.ModelState.IsValid)
            {
                return View("Error");
            }
            Book targetBook = BookProvider.Instance.AllBooks.SingleOrDefault(b => b.Id == vm.BookId);
            User targetUser = UserProvider.Instance.AllUsers.SingleOrDefault(u => u.Id == vm.UserId);

            if (targetBook == null || targetUser == null)
            {
                return View("Error");
            }

            Order order = new Order();
            order.BookId = vm.BookId;
            order.UserId = vm.UserId;
            order.Total = vm.Amount * targetBook.Price;

            return View("Order", order);
        }
예제 #2
0
 public ActionResult Buy()
 {
     BuyViewModel vm = new BuyViewModel() { Limit = 3 };
     return View(vm);
 }