Пример #1
0
        public async Task <IActionResult> Add()
        {
            var UserName = User.Identity.Name;
            var user     = await _userManager.FindByNameAsync(UserName);

            var UserId   = user.Id;
            var entities = _shoppingBoxService.GetCards();

            Order order = new Order();

            order.AddDate  = DateTime.Now;
            order.UserId   = UserId;
            order.UserName = UserName;
            _orderService.Add(order);

            decimal totalPrice = 0;

            foreach (var item in entities)
            {
                OrderDetail detail = new OrderDetail();
                detail.BookId   = item.BookId;
                detail.Quantity = item.Quantity;
                detail.OrderId  = order.Id;

                _orderDetailService.Add(detail);

                totalPrice = _bookService.GetBookById(item.BookId).Price *item.Quantity + totalPrice;

                _shoppingBoxService.DeleteShopCard(item.Id);
            }

            var model = _orderService.GetById(order.Id);

            model.TotalPrice = totalPrice;

            _orderService.SaveChanges();


            TempData["IslemBasarili"] = "Satın Alma işlemi Başarılı olmuştur.";
            return(RedirectToAction("Index"));
        }
Пример #2
0
 public IActionResult DeleteShopCard(int id)
 {
     _shoppingBoxService.DeleteShopCard(id);
     return(Ok());
 }