//public static void CopyToEntity(AgentAdmin agent, LoginRequest request)
 //{
 //    agent.Password = request.password; // app_id
 //    agent.MobileNumber = request.mobile_number;
 //    agent.AppToken = request.push_token;
 //}
 public static void CopyFromEntity(AgentBossLoginDto dto, AgentBoss agentBoss)
 {
     dto.auth_token = agentBoss.AccToken;
     dto.user_id    = agentBoss.AbosID;
     if (dto.user_details == null)
     {
         dto.user_details = new AgentBossDetailsDto();
         CopyFromEntity(dto.user_details, agentBoss);
     }
 }
        public static LoginResponse Login(LoginRequest request)
        {
            request.mobile_number = Common.GetStandardMobileNumber(request.mobile_number);
            LoginResponse response  = new LoginResponse();
            AgentBoss     agentBoss = null;

            try
            {
                using (AgentBossDao dao = new AgentBossDao())
                {
                    string hashPassword = TokenGenerator.GetHashedPassword(request?.password, 49);
                    agentBoss = dao.FindByMobileNumber(request.mobile_number);
                    if (agentBoss == null)
                    {
                        MakeNouserResponse(response);
                        return(response);
                    }
                    if (hashPassword == agentBoss.Password)
                    {
                        response.code         = 1;
                        response.has_resource = 0;
                        //admin. = request.app_id;
                        agentBoss.AppToken  = request.push_token;
                        agentBoss.AppID     = request.app_id;
                        agentBoss.LastLogin = DateTime.Now;
                        string authToken = TokenGenerator.GenerateToken(agentBoss.OwnerName, agentBoss.Password, request.mobile_number);
                        agentBoss.AccToken = authToken;
                        dao.Update(agentBoss);
                        response.code = 0;
                        AgentBossLoginDto dto = new AgentBossLoginDto();
                        AgentBossHelper.CopyFromEntity(dto, agentBoss);
                        response.code         = 0;
                        response.message      = MessagesSource.GetMessage("login.ok");
                        response.has_resource = 1;
                        response.user_login   = dto;
                        return(response);
                    }
                    else
                    {
                        response.code         = 1;
                        response.has_resource = 0;
                        response.message      = MessagesSource.GetMessage("login.fail");
                    }
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }
            return(response);
        }