public ActionResult AgentList(int id, int?page, string name)
        {
            //AgentManagementRepository agentManagementRepository = new AgentManagementRepository();
            //var model = agentManagementRepository.GetAllAgentByPaging().Where(x => x.BranchOfficeId == id).ToList();
            //if (model.Count > 0)
            //    model[0].AgentStatus = true;
            //return PartialView(@"~\Areas\Administrator\Views\DistributorManagement\VUC_AgentList.ascx", model);

            int currentPageIndex = page.HasValue ? page.Value : 1;
            int defaultPageSize  = 50;

            DistributorManagementProvider   distributorManagementProvider = new DistributorManagementProvider();
            DistributorAgentManagementModel model = new DistributorAgentManagementModel();

            if (name != "Distributor")
            {
                model.AgentsList = distributorManagementProvider.AgentsListByBranchOfficeId().Where(x => x.BranchOfficeId == id).ToPagedList(currentPageIndex, defaultPageSize);
            }
            else
            {
                model.AgentsList = distributorManagementProvider.AgentsListByBranchOfficeId().Where(x => x.DistributorId == id).ToPagedList(currentPageIndex, defaultPageSize);
            }
            if (model.AgentsList.Count > 0)
            {
                model.AgentStatus = true;
            }
            model.RedirectedFrom = "BranchOfficeManagement";
            model.BranchOfficeId = id;

            return(View(model));
        }
        public ActionResult AgentList(int id, int?page)
        {
            int currentPageIndex = page.HasValue ? page.Value : 1;
            int defaultPageSize  = 50;

            DistributorManagementProvider   distributorManagementProvider = new DistributorManagementProvider();
            DistributorAgentManagementModel model = new DistributorAgentManagementModel();

            model.AgentsList = distributorManagementProvider.AgentsListByBranchOfficeId().Where(x => x.DistributorId == id).ToPagedList(currentPageIndex, defaultPageSize);
            if (model.AgentsList.Count > 0)
            {
                model.AgentStatus = true;
            }
            model.DistributorId = id;
            return(View(model));
        }
        public List <DistributorAgentManagementModel> AgentsListByBranchOfficeId()
        {
            var result = entity.Agents;
            List <DistributorAgentManagementModel> model = new List <DistributorAgentManagementModel>();

            foreach (var item in result)
            {
                DistributorAgentManagementModel obj = new DistributorAgentManagementModel
                {
                    AgentId          = item.AgentId,
                    AgentName        = item.AgentName,
                    AgencyCode       = item.AgentCode,
                    BranchOfficeId   = item.BranchOffices.BranchOfficeId != 0? item.BranchOffices.BranchOfficeId : 0,
                    DistributorId    = item.Distributors.DistributorId != 0 ? item.Distributors.DistributorId : 0,
                    BranchOfficeName = item.BranchOffices != null ? item.BranchOffices.BranchOfficeName + "(" + item.BranchOffices.BranchOfficeCode + ")" : string.Empty,
                    DistributorName  = item.Distributors != null ? item.Distributors.DistributorName + "(" + item.Distributors.DistributorCode + ")" : string.Empty,
                    Phone            = item.Phone,
                    CreatedOn        = item.CreatedDate
                };
                model.Add(obj);
            }
            return(model.OrderBy(x => x.AgentName).ToList());
        }