public async Task <IActionResult> ClientChangePassword([FromBody] ChangePasswordDTO model)
        {
            var customer = await GetCustomer();

            if (customer == null)
            {
                return(Ok(ResponseDTO.BadRequest("Invalid customers' username.")));
            }

            // Check password
            if (!SecurityHelper.VerifyPassword(model.oldPassword, customer.PasswordHash, customer.PasswordSalt))
            {
                return(Ok(ResponseDTO.BadRequest("Old password is not correct.")));
            }

            // Update password
            byte[] passwordHash, passwordSalt;
            SecurityHelper.CreatePasswordHash(model.newPassword, out passwordHash, out passwordSalt);
            customer.PasswordHash = passwordHash;
            customer.PasswordSalt = passwordSalt;

            await _context.SaveChangesAsync();

            return(Ok(ResponseDTO.OkEmpty()));
        }
        public async Task<IActionResult> ClientCartUpdate([FromBody] List<BodyCartDTO> updateList)
        {
            var customer = await GetCustomerFromSession();
            if (customer == null)
            {
                return Ok(ResponseDTO.BadRequest());
            }

            var cart = await _context.Carts.FirstOrDefaultAsync(o => o.CustomerId == customer.Id);
            if (cart == null)
            {
                return Ok(ResponseDTO.OkEmpty());
            }

            var cartItems = _context.CartItems
                .Include(c => c.Stock).ThenInclude(o => o.Shoes).ThenInclude(o => o.ShoesImages)
                .Include(c => c.Stock).ThenInclude(o => o.Size)
                .Where(o => o.CartId == cart.Id);


            // Update details
            foreach (var detail in updateList)
            {
                var updateItem = cartItems.FirstOrDefault(c => c.Stock.Id == detail.stockId);
                if (updateItem != null)
                {
                    if (detail.quantity > 0)
                    {
                        updateItem.Amount = detail.quantity;
                    }
                    else
                    {
                        _context.CartItems.Remove(updateItem);
                    }
                }
            }
            _context.SaveChanges();


            // Parse responses
            var items = new List<dynamic>();
            foreach (var item in cartItems)
            {
                items.Add(new
                {
                    stockId = item.Stock.Id,
                    shoesId = item.Stock.ShoesId,
                    name = item.Stock.Shoes.Name,
                    sizeName = item.Stock.Size.Name,
                    quantity = item.Amount,
                    price = item.Stock.Shoes.Price,
                    image = item.Stock.Shoes.ShoesImages.FirstOrDefault().ImagePath
                });
            }

            return Ok(ResponseDTO.Ok(items, items.Count));
        }
        public async Task<IActionResult> ClientCartGet()
        {
            var customer = await GetCustomerFromSession();
            if (customer == null)
            {
                return Ok(ResponseDTO.BadRequest());
            }

            var cart = await _context.Carts.FirstOrDefaultAsync(o => o.CustomerId == customer.Id);
            if (cart == null)
            {
                return Ok(ResponseDTO.OkEmpty());
            }

            var cartItems = await _context.CartItems
                .Include(c => c.Stock).ThenInclude(o => o.Shoes).ThenInclude(o => o.ShoesImages)
                .Include(c => c.Stock).ThenInclude(o => o.Size)
                .Where(o => o.CartId == cart.Id)
                .ToListAsync();

            var items = new List<dynamic>();
            foreach (var item in cartItems)
            {
                items.Add(new
                {
                    stockId = item.Stock.Id,
                    shoesId = item.Stock.ShoesId,
                    name = item.Stock.Shoes.Name,
                    sizeName = item.Stock.Size.Name,
                    quantity = item.Amount,
                    price = item.Stock.Shoes.Price,
                    image = item.Stock.Shoes.ShoesImages.FirstOrDefault().ImagePath
                });
            }

            return Ok(ResponseDTO.Ok(items, items.Count));
        }