public async Task <ActionResult <Account_AccountDTO> > ChangePassword([FromBody] Account_ChangePasswordDTO Account_ChangePasswordDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            if (!Account_ChangePasswordDTO.Password.Equals(Account_ChangePasswordDTO.ConfirmPassword))
            {
                return(BadRequest("Xác nhận mật khẩu không đúng."));
            }

            Account Account = new Account
            {
                Id          = ExtractUserId(),
                Password    = Account_ChangePasswordDTO.OldPassword,
                NewPassword = Account_ChangePasswordDTO.Password,
            };

            Account = await AccountService.ChangePassword(Account);

            Account_AccountDTO Account_AccountDTO = new Account_AccountDTO(Account);

            if (!Account.IsValidated)
            {
                return(BadRequest("Bạn đã nhập sai mật khẩu cũ."));
            }
            return(Ok(Account_AccountDTO));
        }
        public async Task <ActionResult <Account_AccountDTO> > Login([FromBody] Account_LoginDTO Account_LoginDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            Account Account = new Account
            {
                Email    = Account_LoginDTO.Email,
                Password = Account_LoginDTO.Password
            };

            Account = await AccountService.Login(Account);

            if (!Account.IsValidated)
            {
                switch (Account.Errors.Values.FirstOrDefault())
                {
                case "EmailNotExisted":
                    return(BadRequest("Email không tồn tại."));

                case "PasswordNotMatch":
                    return(BadRequest("Bạn đã nhập sai mật khẩu."));
                }
            }
            Response.Cookies.Append("Token", Account.Token);
            Account_AccountDTO Account_AccountDTO = new Account_AccountDTO(Account);

            Account_AccountDTO.Token = Account.Token;
            return(Ok(Account_AccountDTO));
        }
        public async Task <ActionResult <Account_AccountDTO> > Update([FromBody] Account_AccountDTO Account_AccountDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            Account Account = new Account
            {
                Id          = Account_AccountDTO.Id,
                Phone       = Account_AccountDTO.Phone,
                DisplayName = Account_AccountDTO.DisplayName,
                Address     = Account_AccountDTO.Address,
                Avatar      = Account_AccountDTO.Avatar,
                Dob         = Account_AccountDTO.Dob
            };

            Account.Id = ExtractUserId();
            Account    = await AccountService.Update(Account);

            Account_AccountDTO = new Account_AccountDTO(Account);
            if (Account.IsValidated)
            {
                return(Account_AccountDTO);
            }
            else
            {
                return(BadRequest("Số điện thoại không được bỏ trống."));
            }
        }
        public async Task <ActionResult <Account_AccountDTO> > Register([FromBody] Account_RegisterDTO Account_RegisterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            if (!Account_RegisterDTO.Password.Equals(Account_RegisterDTO.ConfirmPassword))
            {
                return(BadRequest("Xác nhận mật khẩu không đúng."));
            }

            Account Account = new Account
            {
                Email    = Account_RegisterDTO.Email,
                Phone    = Account_RegisterDTO.Phone,
                Password = Account_RegisterDTO.Password
            };

            Account = await AccountService.Create(Account);

            Account_AccountDTO Account_AccountDTO = new Account_AccountDTO(Account);

            if (!Account.IsValidated)
            {
                switch (Account.Errors.Values.FirstOrDefault())
                {
                case "EmailExisted":
                    return(BadRequest("Email đã tồn tại."));

                case "EmailInvalid":
                    return(BadRequest("Email không hợp lệ."));

                case "PhoneEmpty":
                    return(BadRequest("Số điện thoại không được bỏ trống."));
                }
            }
            return(Ok(Account_AccountDTO));
        }
        public async Task <ActionResult <Account_AccountDTO> > LikeFood([FromBody] Account_AccountDTO Account_AccountDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            var     Id      = ExtractUserId();
            Account Account = new Account
            {
                Id = Id,
                AccountFoodFavorites = Account_AccountDTO.Account_AccountFoodFavorites.Select(a => new AccountFoodFavorite
                {
                    AccountId = Id,
                    FoodId    = a.FoodId
                }).ToList()
            };

            Account = await AccountService.LikeFood(Account);

            Account_AccountDTO = new Account_AccountDTO(Account);
            return(Ok(Account_AccountDTO));
        }