public JsonResult CreatePointOfInterest([FromBody] AccountForCreationDto account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check value enter from the form
                if (account == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationAccount));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_ACCOUNT)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //Check email enter from the form exist in the database
                if (!_accountRepository.EmailExist(account.Email))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailExist));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_EXIST)));
                }

                //This is send email to vertified account
                SendGmail.SendVertified(account.Email);

                //Hash new password
                account.Password = PasswordUtil.CreateMD5(account.Password);

                //Map data enter from the form to account entity
                var finalAccount = Mapper.Map <PPT.Database.Entities.AccountEntity>(account);

                //This is query insert account
                _accountRepository.Register(finalAccount);

                if (!_accountRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.registerSuccess));
                return(Json(MessageResult.GetMessage(MessageType.REGISTER_SUCCESS)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
        public JsonResult ForgotPassword(string email)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check value enter from the form
                if (email == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notEnterEmail));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_ENTER_EMAIL)));
                }

                //Check email enter from the form not exist in the database
                if (_accountRepository.EmailExist(email))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailNotExist));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_NOT_EXIST)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                //Check email enter from the form exist in the database
                if (!_accountRepository.EmailExist(email))
                {
                    //This is send new password through email
                    string code = SendGmail.ForgotPassword(email);

                    AccountEntity accountEntity = _accountRepository.GetAccountByEmail(email);
                    //This is update new password
                    accountEntity.Password = PasswordUtil.CreateMD5(code);
                }

                if (!_accountRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.sendPassword));
                return(Json(MessageResult.GetMessage(MessageType.SEND_PASSWORD)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
        public JsonResult UpdateAccountPatch([FromBody] ChangingPassword account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                //Check id account exist in the database
                if (!_accountRepository.AccountExists(account.accountId))
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountNotFound));
                    return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_NOT_FOUND)));
                }

                //Check value enter from the form
                if (account == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notInformationAccount));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_INFORMATION_ACCOUNT)));
                }

                if (!ModelState.IsValid)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notFound));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_FOUND)));
                }

                var oldPass = PasswordUtil.CreateMD5(account.oldPassword);

                //This is get all information of account
                var accountEntity = _accountRepository.GetAccountById(account.accountId);

                if (accountEntity == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailAndPasswordWrong));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_AND_PASSWORD_WRONG)));
                }

                //This is check old password
                if (accountEntity.Password != oldPass)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.oldPasswordNotTrue));
                    return(Json(MessageResult.GetMessage(MessageType.OLD_PASSWORD_NOT_TRUE)));
                }

                //This is update new password
                accountEntity.Password = PasswordUtil.CreateMD5(account.newPassword);

                if (!_accountRepository.Save())
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.badRequest));
                    return(Json(MessageResult.GetMessage(MessageType.BAD_REQUEST)));
                }

                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.accountUpdated));
                return(Json(MessageResult.GetMessage(MessageType.ACCOUNT_UPDATED)));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }
        public JsonResult Login([FromBody] AccountDto account)
        {
            string functionName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            try
            {
                if (account == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.notEnterEmail));
                    return(Json(MessageResult.GetMessage(MessageType.NOT_ENTER_EMAIL)));
                }

                //This is hash password
                string hastPwd = PasswordUtil.CreateMD5(account.password);

                //Query account following email and password
                AccountEntity accountEntity = _accountRepository.LoginAccount(account.email, hastPwd);

                if (accountEntity == null)
                {
                    Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(Constants.emailAndPasswordWrong));
                    return(Json(MessageResult.GetMessage(MessageType.EMAIL_AND_PASSWORD_WRONG)));
                }

                //This is get list role of account entity
                IEnumerable <AccountRoleEntity> listRole = _accountRepository.GetAccountRoles(accountEntity.AccountId);

                //This is set data for login result
                LoginResult result = new LoginResult();


                HttpContext.Session.SetInt32("accountId", account.accountId);
                result.accountId   = accountEntity.AccountId;
                result.email       = accountEntity.Email;
                result.password    = accountEntity.Password;
                result.fullName    = accountEntity.FullName;
                result.phoneNumber = accountEntity.Phone;
                result.address     = accountEntity.Address;
                var a = HttpContext.Session.Get("accountId");
                result.Session = a;
                var listRoles = new List <string>();

                List <RoleEntity> roles = new List <RoleEntity>();

                //Browser the elements of list role
                foreach (var poi in listRole)
                {
                    RoleEntity roleEntity = _accountRepository.GetRole(poi.RoleId);
                    roles.Add(roleEntity);
                }

                foreach (var item in roles)
                {
                    listRoles.Add(item.NameRole);
                }

                result.Roles = listRoles;
                return(Json(result));
            }
            catch (Exception ex)
            {
                Log4Net.log.Error(className + "." + functionName + " - " + Log4Net.AddErrorLog(ex.Message));
                return(Json(MessageResult.ShowServerError(ex.Message)));
            }
        }