예제 #1
0
        public int AddOrder(int userid)
        {
            var order = new Order()
            {
                CreateDate = DateTime.Now,
                IsFainaly  = false,
                UserId     = userid.ToString()
            };

            _context.Add(order);
            _context.SaveChanges();
            return(order.OrderId);
        }
예제 #2
0
        public IActionResult Order(int id)
        {
            var CurentUserId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var Order        = _context.Orders.SingleOrDefault(o => o.UserId == CurentUserId && !o.IsFainaly);

            if (Order == null)
            {
                var details = new Order
                {
                    CreateDate = DateTime.Now,
                    Sum        = 0,
                    IsFainaly  = false,
                    UserId     = CurentUserId,
                };
                _context.Add(details);
                _context.SaveChanges();
                _context.Add(new OrdeeDetails
                {
                    OrderId = details.OrderId,
                    Price   = _context.BookStors.Find(id).Price,
                    Count   = 1,
                    BookId  = id
                });
                _context.SaveChanges();
                SumOrder(details.OrderId);
            }
            else
            {
                var Detail = _context.OrdeeDetails.SingleOrDefault(d => d.OrderId == Order.OrderId && d.BookId == id);
                if (Detail == null)
                {
                    _context.Add(new OrdeeDetails
                    {
                        OrderId = Order.OrderId,
                        Price   = _context.BookStors.Find(id).Price,
                        Count   = 1,
                        BookId  = id
                    });
                }
                else
                {
                    Detail.Count += 1;
                    _context.Update(Detail);
                    SumOrder(Detail.OrderId);
                }
                _context.SaveChanges();
            }


            return(RedirectToAction("ShowOrder"));
        }