Ejemplo n.º 1
0
        public async Task <IActionResult> GetAddressByUser([FromQuery] bool?IsDefault)
        {
            var addressList = await _context.Addresses.ToListAsync();


            string access_token = await HttpContext.GetTokenAsync("access_token");

            var user = _token.GetPayloadAsync(access_token);

            if (user != null)
            {
                addressList = addressList.Where(a => a.UserId == user.UserId).ToList();
            }


            if (IsDefault != null)
            {
                addressList = addressList.Where(a => a.IsDefault == IsDefault).ToList();
            }

            // if (addressList.Count() == 1)
            // {
            //     var address = addressList.SingleOrDefault();
            //     return Ok(new { success = true, data = address});
            // }
            return(Ok(new { success = true, data = addressList }));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetOrder([FromQuery] OrderFilter filter)
        {
            var orderSource = await _context.Orders.Include(o => o.OrderItems).ToListAsync();

            // var order = orderSource;
            string access_token = await HttpContext.GetTokenAsync("access_token");

            var user = _token.GetPayloadAsync(access_token);

            var order = orderSource.Where(o => o.BuyerId == user.UserId).ToList();

            if (filter.Status != 0)
            {
                order = order.Where(o => o.Status == filter.Status).ToList();
            }

            var totalAllPrice = 0;

            foreach (var item in order)
            {
                if (item.Status != 4)
                {
                    totalAllPrice += item.Total;
                }
            }

            return(Ok(new { success = true, filter = filter, data = order, totalAllPrice = totalAllPrice }));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> GetCart()
        {
            string access_token = await HttpContext.GetTokenAsync("access_token");

            var user = _token.GetPayloadAsync(access_token);

            var data = await _cartService.GetCartAsync(user.UserId);

            return(Ok(new { success = true, data = data }));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostBook([FromForm] Book book)
        {
            string access_token = await HttpContext.GetTokenAsync("access_token");

            var user = _token.GetPayloadAsync(access_token);

            book.UserId   = user.UserId;
            book.FullName = user.Fullname;
            var result = await _bookService.PostBookAsync(book);

            return(result);
        }