public void AddRoute(RouteLookup routeLookup)
 {
     if (routeLookup != null)
     {
         DistributorSalemanRoute dsr = new DistributorSalemanRoute()
                                           {
                                               CostCentreId = UserLookup.CostCentreId,
                                               MasterId = Guid.NewGuid(),
                                               RouteId = routeLookup.Id,
                                               RouteName = routeLookup.RouteName
                                           };
         DistributorSalemanRoute.Add(dsr);
     }
 }
        private void GetDistributorSalemanRoute()
        {
            using (StructureMap.IContainer c = NestedContainer)
            {
                DistributorSalemanRoute.Clear();
                
                List<User> userList = Using<IUserRepository>(c).GetAll(true).ToList();
                if (UserLookup == null)
                    UserLookup = UserLookupList.FirstOrDefault(n => n.Id == Guid.Empty);
                if(UserLookup==null)
                {
                  UserLookup = new UserLookup
                    {
                        Id = Guid.Empty,
                        Username = GetLocalText("sl.userroute.salesman.default") /* "---Select Salesman---" */
                    };
                }

                if (UserLookup.Id == Guid.Empty)
                {
                    var salesmanRoutes = Using<ISalesmanRouteRepository>(c).GetAll(ShowInactive).ToList();
                    salesmanRoutes.Where(n => n.Route != null).ToList()
                                  .ForEach(p =>
                                      {
                                          try
                                          {
                                              var item = new DistributorSalemanRoute
                                                  {
                                                      RouteId = p.Route.Id,
                                                      RouteName = p.Route.Name,
                                                      MasterId = p.Id,
                                                      CostCentreId = p.DistributorSalesmanRef.Id,

                                                      SalesmanNames = userList.Where(
                                                          w => w.CostCentre == p.DistributorSalesmanRef.Id)
                                                                              .First() != null
                                                                          ? userList
                                                                                .Where(
                                                                                    w =>
                                                                                    w.CostCentre ==
                                                                                    p.DistributorSalesmanRef.Id)
                                                                                .First().Username
                                                                          : "",

                                                      EntityStatus = (int) p._Status
                                                  };
                                              if (item.EntityStatus == (int) EntityStatus.Active)
                                                  item.HlkDeactivateContent =
                                                      GetLocalText("sl.userroute.grid.col.deactivate");
                                              else if (item.EntityStatus == (int) EntityStatus.Inactive)
                                                  item.HlkDeactivateContent =
                                                      GetLocalText("sl.userroute.grid.col.activate");

                                              DistributorSalemanRoute.Add(item);
                                          }
                                          catch
                                          {
                                          }
                                      });
                }
                else
                {
                    var salesmanRoutes = Using<ISalesmanRouteRepository>(c).GetAll(ShowInactive).ToList();
                    salesmanRoutes.Where(n => n.Route != null).OrderBy(o => o.Route.Name)
                                  .Where(n => n.DistributorSalesmanRef.Id == UserLookup.CostCentreId)
                                  .ToList()
                                  .ForEach(p =>
                                      {
                                          var item = new DistributorSalemanRoute
                                              {
                                                  RouteId = p.Route.Id,
                                                  RouteName = p.Route.Name,
                                                  MasterId = p.Id,
                                                  CostCentreId = p.DistributorSalesmanRef.Id,
                                                  SalesmanNames =
                                                      userList.Where(w => w.CostCentre == p.DistributorSalesmanRef.Id)
                                                              .First()
                                                              .Username,
                                                  EntityStatus = (int) p._Status
                                              };

                                          if (item.EntityStatus == (int) EntityStatus.Active)
                                              item.HlkDeactivateContent =
                                                  GetLocalText("sl.userroute.grid.col.deactivate");
                                          else if (item.EntityStatus == (int) EntityStatus.Inactive)
                                              item.HlkDeactivateContent =
                                                  GetLocalText("sl.userroute.grid.col.activate");

                                          DistributorSalemanRoute.Add(item);
                                      });
                }
            }
        }