Пример #1
0
        //
        // GET: /ServicePoint/
        public ActionResult Index(string id = "", string territoryguid = "")
        {
            Logger.Debug("Inside People Controller- Index");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    DropdownValues();
                    var regionList = new RegionViewModel();
                    regionList.Region = new List <RegionModel>();

                    var appRegion = _IRegionRepository.GetRegionByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();

                    regionList.Region.Add(new RegionModel {
                        Name = "All Regions", RegionGUID = "", Description = "", OrganizationGUID = ""
                    });
                    foreach (var region in appRegion.ToList())
                    {
                        regionList.Region.Add(new RegionModel {
                            Name = region.Name, RegionGUID = region.RegionGUID.ToString(), Description = region.Description, OrganizationGUID = region.OrganizationGUID != null ? region.OrganizationGUID.ToString() : Guid.Empty.ToString()
                        });
                    }

                    var territoryList = new TerritoryViewModel();
                    territoryList.Territory = new List <TerritoryModel>();
                    var appTerritory = new List <Territory>();
                    if (string.IsNullOrEmpty(id) || id == Guid.Empty.ToString())
                    {
                        appTerritory = _ITerritoryRepository.GetTerritoryByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                    }
                    else
                    {
                        appTerritory = _ITerritoryRepository.GetTerritoryByRegionGUID(new Guid(id)).ToList();
                    }
                    territoryList.Territory.Add(new TerritoryModel {
                        Name = "All Territories", TerritoryGUID = "", RegionGUID = "", Description = "", OrganizationGUID = ""
                    });
                    foreach (var territory in appTerritory.ToList())
                    {
                        territoryList.Territory.Add(new TerritoryModel {
                            Name = territory.Name, RegionGUID = territory.RegionGUID != null ? territory.RegionGUID.ToString() : Guid.Empty.ToString(), TerritoryGUID = territory.TerritoryGUID.ToString(), Description = territory.Description, OrganizationGUID = territory.OrganizationGUID != null ? territory.OrganizationGUID.ToString() : Guid.Empty.ToString()
                        });
                    }

                    var marketList = new ServicePointViewModel();
                    marketList.MarketList = new List <ServicePointModel>();
                    var appMarket = new List <Market>();
                    if (string.IsNullOrEmpty(id) && string.IsNullOrEmpty(territoryguid))
                    {
                        // if (Session["UserType"].ToString() == "ENT_A")
                        {
                            appMarket = _IMarketRepository.GetMarketByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), 0).ToList();
                        }
                    }
                    else if (!string.IsNullOrEmpty(id) && string.IsNullOrEmpty(territoryguid))
                    {
                        appMarket             = _IMarketRepository.GetMarketByRegionGUID(new Guid(id), 0).ToList();
                        ViewBag.TerritoryGUID = id;
                    }
                    else if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(territoryguid))
                    {
                        appMarket             = _IMarketRepository.GetMarketByRegionGUIDandTerritoryGUID(new Guid(territoryguid), new Guid(id), 0).ToList();
                        ViewBag.RegionGUID    = territoryguid;
                        ViewBag.TerritoryGUID = id;
                    }
                    foreach (var market in appMarket.ToList())
                    {
                        marketList.MarketList.Add(new ServicePointModel
                        {
                            MarketGUID         = market.MarketGUID.ToString(),
                            UserGUID           = market.UserGUID.ToString(),
                            OrganizationGUID   = market.OrganizationGUID.ToString(),
                            OwnerGUID          = market.OwnerGUID.ToString(),
                            MarketName         = market.MarketName,
                            MarketPhone        = market.MarketPhone,
                            PrimaryContactGUID = market.PrimaryContactGUID.ToString(),
                            FirstName          = market.FirstName,
                            LastName           = market.LastName,
                            MobilePhone        = market.MobilePhone,
                            HomePhone          = market.HomePhone,
                            Emails             = market.Emails,
                            AddressLine1       = market.AddressLine1,
                            AddressLine2       = market.AddressLine2,
                            City          = market.City,
                            State         = market.State,
                            Country       = market.Country,
                            ZipCode       = market.ZipCode,
                            RegionGUID    = market.RegionGUID.ToString(),
                            TerritoryGUID = market.TerritoryGUID.ToString(),
                            RegionName    = market.RegionGUID != null ? _IRegionRepository.GetRegionNameByRegionGUID(new Guid(market.RegionGUID.ToString())) : "",
                            TerritoryName = market.TerritoryGUID != null ? _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(market.TerritoryGUID.ToString())) : "",
                        });
                    }

                    var viewModel = new ServicePointViewModel();
                    viewModel.RegionModel    = regionList.Region.AsEnumerable();
                    viewModel.TerritoryModel = territoryList.Territory.AsEnumerable();
                    viewModel.MarketModel    = marketList.MarketList.AsEnumerable();

                    return(View(viewModel));
                }
                else
                {
                    return(RedirectToAction("SessionTimeOut", "User"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(RedirectToAction("Login", "User"));
            }
        }