Ejemplo n.º 1
0
        public ActionResult Edit(string id = "")
        {
            Logger.Debug("Inside ServicePoint Controller- Create Http Post");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    DropdownValues();
                    Market            EditMarket = _IMarketRepository.GetMarketByID(new Guid(id));
                    ServicePointModel Market     = new ServicePointModel();
                    if (EditMarket != null)
                    {
                        Market.MarketGUID       = EditMarket.MarketGUID.ToString();
                        Market.IsDefault        = Convert.ToBoolean(EditMarket.IsDefault);
                        Market.UserGUID         = EditMarket.UserGUID.ToString();
                        Market.EntityType       = Convert.ToInt32(EditMarket.EntityType);
                        Market.OrganizationGUID = EditMarket.OrganizationGUID != null?EditMarket.OrganizationGUID.ToString() : Guid.Empty.ToString();

                        Market.OwnerGUID = EditMarket.OwnerGUID != null?EditMarket.OwnerGUID.ToString() : Guid.Empty.ToString();

                        Market.MarketName         = EditMarket.MarketName;
                        Market.PrimaryContactGUID = EditMarket.PrimaryContactGUID != null?EditMarket.PrimaryContactGUID.ToString() : Guid.Empty.ToString();

                        Market.RegionGUID = EditMarket.RegionGUID != null?EditMarket.RegionGUID.ToString() : Guid.Empty.ToString();

                        Market.TerritoryGUID = EditMarket.TerritoryGUID != null?EditMarket.TerritoryGUID.ToString() : Guid.Empty.ToString();

                        Market.FirstName    = EditMarket.FirstName;
                        Market.LastName     = EditMarket.LastName;
                        Market.MobilePhone  = EditMarket.MobilePhone;
                        Market.MarketPhone  = EditMarket.MarketPhone;
                        Market.HomePhone    = EditMarket.HomePhone;
                        Market.Emails       = EditMarket.Emails;
                        Market.AddressLine1 = EditMarket.AddressLine1;
                        Market.AddressLine2 = EditMarket.AddressLine2;
                        Market.City         = EditMarket.City;
                        Market.State        = EditMarket.State;
                        Market.Country      = EditMarket.Country;
                        Market.ZipCode      = EditMarket.ZipCode;
                        Market.CreateDate   = Convert.ToDateTime(EditMarket.CreateDate);
                        if (!string.IsNullOrEmpty(Market.RegionGUID))
                        {
                            var TerritoryDetails = _ITerritoryRepository.GetTerritoryByRegionGUID(new Guid(Market.RegionGUID)).ToList().OrderBy(r => r.Name).Select(r => new SelectListItem
                            {
                                Value = r.TerritoryGUID.ToString(),
                                Text  = r.Name
                            });
                            ViewBag.TerritoryDetails = new SelectList(TerritoryDetails, "Value", "Text");
                        }
                        return(View(Market));
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(RedirectToAction("SessionTimeOut", "User"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(View());
            }
        }
Ejemplo n.º 2
0
        public ActionResult EditJobDetails(JobViewModel _jobdetails)
        {
            Logger.Debug("Inside People Controller- Create");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    List <JobProgressViewModel> pJobProgressViewModel = new List <JobProgressViewModel>();

                    TempData["TabName"] = "Details";
                    DropdownValues();
                    JobViewModel _job = _jobdetails;
                    if (ModelState.IsValid)
                    {
                        Job job = new Job();
                        job.JobGUID = new Guid(_job.JobModel.JobIndexGUID.ToString());
                        Int16 jobclass;

                        if (_job.JobModel.JobClass != null && !string.IsNullOrEmpty(_job.JobModel.JobClass))
                        {
                            string[] pjobclass = _job.JobModel.JobClass.Split(',');
                            if (pjobclass.Count() > 1)
                            {
                                if (short.TryParse(pjobclass[0], out jobclass))
                                {
                                    job.JobClass = jobclass;
                                }
                                job.JobForm = _IJobSchemaRepository.GetJobSchemabyJobFormID(new Guid(pjobclass[1])).JobForm1;
                            }
                        }
                        //job.JobFormGUID = _job.JobModel.JobLogicalID;
                        //  job.JobID = 0;
                        job.JobReferenceNo   = _job.JobModel.JobReferenceNo;
                        job.IsDeleted        = false;
                        job.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                        if (_job.JobModel.RegionCode != Guid.Empty)
                        {
                            job.RegionGUID = _job.JobModel.RegionCode;
                        }
                        else
                        {
                            job.RegionGUID = null;
                        }
                        if (_job.JobModel.TerritoryCode != Guid.Empty)
                        {
                            job.TerritoryGUID = _job.JobModel.TerritoryCode;
                        }
                        else
                        {
                            job.TerritoryGUID = null;
                        }
                        job.LocationType = 1;
                        if (_job.JobModel.CustGUID != Guid.Empty)
                        {
                            job.CustomerGUID = _job.JobModel.CustGUID;
                        }
                        else
                        {
                            job.CustomerGUID = null;
                        }
                        if (_job.JobModel.StopsGUID != Guid.Empty)
                        {
                            job.CustomerStopGUID = _job.JobModel.StopsGUID;
                        }
                        else
                        {
                            job.CustomerStopGUID = null;
                        }
                        if (job.CustomerStopGUID != null)
                        {
                            Market  Market  = _IMarketRepository.GetMarketByID(new Guid(job.CustomerStopGUID.ToString()));
                            LatLong latLong = new LatLong();
                            latLong            = GetLatLngCode(Market.AddressLine1, Market.AddressLine2, Market.City, Market.State, Market.Country, Market.ZipCode);
                            job.ServiceAddress = Market.AddressLine1 + "," + Market.AddressLine2 + "," + Market.City + "," + Market.State + "," + Market.Country + "," + Market.ZipCode;
                            job.Latitude       = latLong.Latitude;
                            job.Longitude      = latLong.Longitude;
                        }
                        else
                        {
                            job.ServiceAddress = "";
                            job.Latitude       = null;
                            job.Longitude      = null;
                        }
                        job.StatusCode      = 1;
                        job.JobName         = _job.JobModel.JobName;
                        job.IsSecheduled    = _job.JobModel.IsScheduled == "true" ? true : false;
                        job.ManagerUserGUID = new Guid(Session["UserGUID"].ToString());

                        double duration;
                        if (double.TryParse(_job.JobModel.EstimatedDuration.ToString(), out duration))
                        {
                            job.EstimatedDuration = duration * 3600;
                        }
                        else
                        {
                            job.EstimatedDuration = 0;
                        }

                        job.ScheduledStartTime = Convert.ToDateTime(_job.JobModel.PreferredStartTime);
                        job.PreferedStartTime  = Convert.ToDateTime(_job.JobModel.PreferredStartTime);
                        job.PreferedEndTime    = Convert.ToDateTime(_job.JobModel.PreferredEndTime);
                        job.ActualStartTime    = Convert.ToDateTime(_job.JobModel.ActualStartTime);
                        job.ActualEndTime      = Convert.ToDateTime(_job.JobModel.ActualEndTime);


                        //  job.JobForm = _IJobSchemaRepository.GetJobSchemabyJobFormID(_job.JobModel.JobLogicalID).JobForm1;
                        job.CreateDate       = DateTime.UtcNow;
                        job.CreateBy         = new Guid(Session["UserGUID"].ToString());
                        job.LastModifiedDate = DateTime.UtcNow;
                        job.LastModifiedBy   = new Guid(Session["UserGUID"].ToString());

                        int result = _IJobRepository.UpdateJob(job);
                        //int result = _IJobRepository.Save();
                        if (result > 0)
                        {
                            // return RedirectToAction("Index", "JobDetails", new { jobindexguid = _job.JobModel.JobIndexGUID.ToString() });
                            return(RedirectToAction("Index", "JobStatus"));
                        }
                        else
                        {
                            if (Session["OrganizationGUID"] != null)
                            {
                                Job      _job1 = _IJobRepository.GetJobByID(new Guid(_job.JobModel.JobIndexGUID.ToString()));
                                JobModel job1  = new JobModel();
                                job1.JobIndexGUID = _job1.JobGUID;
                                //     job1.JobLogicalID = _IJobSchemaRepository.GetJobFormIDfromJobForm(_job1.JobForm);
                                job1.JobReferenceNo     = _job1.JobReferenceNo;
                                job1.JobName            = _job1.JobName;
                                job1.CustGUID           = _job1.CustomerGUID != null ? new Guid(_job1.CustomerGUID.ToString()) : Guid.Empty;
                                job1.IsScheduled        = _job1.IsSecheduled == true ? "true" : "false";
                                job1.EstimatedDuration  = _job1.EstimatedDuration;
                                job1.ActualStartTime    = Convert.ToDateTime(_job1.ActualStartTime).ToString("MM/dd/yy HH:mm");
                                job1.ActualEndTime      = Convert.ToDateTime(_job1.ActualEndTime).ToString("MM/dd/yy HH:mm");
                                job1.PreferredStartTime = Convert.ToDateTime(_job1.PreferedStartTime).ToString("MM/dd/yy HH:mm");
                                job1.PreferredEndTime   = Convert.ToDateTime(_job1.PreferedEndTime).ToString("MM/dd/yy HH:mm");
                                job1.RegionCode         = _job1.RegionGUID != null ? new Guid(_job1.RegionGUID.ToString()) : Guid.Empty;
                                job1.TerritoryCode      = _job1.TerritoryGUID != null ? new Guid(_job1.TerritoryGUID.ToString()) : Guid.Empty;
                                job1.StopsGUID          = _job1.CustomerStopGUID != null ? new Guid(_job1.CustomerStopGUID.ToString()) : Guid.Empty;
                                job1.CustomerName       = _job1.CustomerGUID != null?_IJobRepository.GetCustomerName(new Guid(_job1.CustomerGUID.ToString())) : "";

                                job1.CreateDate = _job1.CreateDate;
                                int StatusCode;;
                                if (int.TryParse(_job1.StatusCode.ToString(), out StatusCode))
                                {
                                    job1.Status = StatusCode;
                                }
                                else
                                {
                                    job1.Status = 0;
                                }

                                var placeList = new PlaceViewModel();
                                placeList.PlaceList = new List <PlaceModel>();
                                var appPlace = new List <Place>();
                                DropdownValues();
                                appPlace = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();

                                placeList.PlaceList.Add(new PlaceModel
                                {
                                    PlaceGUID        = Guid.Empty.ToString(),
                                    PlaceName        = "All",
                                    UserGUID         = "",
                                    OrganizationGUID = "",
                                });

                                foreach (var place in appPlace.ToList())
                                {
                                    placeList.PlaceList.Add(new PlaceModel
                                    {
                                        PlaceGUID        = place.PlaceGUID.ToString(),
                                        PlaceID          = place.PlaceID,
                                        PlaceName        = place.PlaceName,
                                        UserGUID         = place.UserGUID.ToString(),
                                        OrganizationGUID = place.OrganizationGUID != null ? place.OrganizationGUID.ToString() : Guid.Empty.ToString(),
                                    });
                                }

                                var marketList = new MarketViewModel();
                                marketList.MarketList = new List <MarketModel>();
                                var appMarket = new List <Market>();
                                // if (Session["UserType"].ToString() == "ENT_A")
                                {
                                    appMarket = _IMarketRepository.GetMarketByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), 1).ToList();
                                }
                                //else
                                //{
                                //    appMarket = _IMarketRepository.GetMarketByUserGUID(new Guid(Session["UserGUID"].ToString()), 1).ToList();
                                //}

                                foreach (var market in appMarket.ToList())
                                {
                                    marketList.MarketList.Add(new MarketModel
                                    {
                                        MarketGUID         = market.MarketGUID.ToString(),
                                        UserGUID           = market.UserGUID != null ? market.UserGUID.ToString() : Guid.Empty.ToString(),
                                        OrganizationGUID   = market.OrganizationGUID != null ? market.OrganizationGUID.ToString() : Guid.Empty.ToString(),
                                        OwnerGUID          = market.OwnerGUID != null ? market.OwnerGUID.ToString() : Guid.Empty.ToString(),
                                        MarketName         = market.MarketName,
                                        MarketPhone        = market.MarketPhone,
                                        PrimaryContactGUID = market.PrimaryContactGUID != null ? market.PrimaryContactGUID.ToString() : Guid.Empty.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 != null ? market.RegionGUID.ToString() : Guid.Empty.ToString(),
                                        TerritoryGUID = market.TerritoryGUID != null ? market.TerritoryGUID.ToString() : Guid.Empty.ToString(),
                                        RegionName    = market.RegionGUID != null ? _IRegionRepository.GetRegionNameByRegionGUID(new Guid(market.RegionGUID.ToString())) : "",
                                        TerritoryName = market.TerritoryGUID != null ? _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(market.TerritoryGUID.ToString())) : "",
                                    });
                                }
                                pJobProgressViewModel = getJobProgress(_job.JobModel.JobIndexGUID.ToString());
                                var viewModel = new JobViewModel();
                                viewModel.Place           = placeList.PlaceList;
                                viewModel.Market          = marketList.MarketList;
                                viewModel.JobProgressList = pJobProgressViewModel;
                                viewModel.JobModel        = job1;
                                return(View("Index", viewModel));
                                //return RedirectToAction("Index", "JobDetails", new { jobindexguid = _job.JobModel.JobIndexGUID.ToString() });
                            }
                            else
                            {
                                return(RedirectToAction("../User/Login"));
                            }
                        }
                    }
                    else
                    {
                        if (Session["OrganizationGUID"] != null)
                        {
                            Job      _job1 = _IJobRepository.GetJobByID(new Guid(_job.JobModel.JobIndexGUID.ToString()));
                            JobModel job1  = new JobModel();
                            job1.JobIndexGUID = _job1.JobGUID;
                            //  job1.JobLogicalID = _IJobSchemaRepository.GetJobFormIDfromJobForm(_job1.JobForm);

                            job1.JobReferenceNo     = _job1.JobReferenceNo;
                            job1.JobName            = _job1.JobName;
                            job1.CustGUID           = _job1.CustomerGUID != null ? new Guid(_job1.CustomerGUID.ToString()) : Guid.Empty;
                            job1.IsScheduled        = _job1.IsSecheduled == true ? "true" : "false";
                            job1.EstimatedDuration  = _job1.EstimatedDuration;
                            job1.ActualStartTime    = Convert.ToDateTime(_job1.ActualStartTime).ToString("MM/dd/yy HH:mm");
                            job1.ActualEndTime      = Convert.ToDateTime(_job1.ActualEndTime).ToString("MM/dd/yy HH:mm");
                            job1.PreferredStartTime = Convert.ToDateTime(_job1.PreferedStartTime).ToString("MM/dd/yy HH:mm");
                            job1.PreferredEndTime   = Convert.ToDateTime(_job1.PreferedEndTime).ToString("MM/dd/yy HH:mm");
                            job1.RegionCode         = _job1.RegionGUID != null ? new Guid(_job1.RegionGUID.ToString()) : Guid.Empty;
                            job1.TerritoryCode      = _job1.TerritoryGUID != null ? new Guid(_job1.TerritoryGUID.ToString()) : Guid.Empty;
                            job1.StopsGUID          = _job1.CustomerStopGUID != null ? new Guid(_job1.CustomerStopGUID.ToString()) : Guid.Empty;
                            job1.CustomerName       = _job1.CustomerGUID != null?_IJobRepository.GetCustomerName(new Guid(_job1.CustomerGUID.ToString())) : "";

                            job1.CreateDate = _job1.CreateDate;

                            int StatusCode;;
                            if (int.TryParse(_job1.StatusCode.ToString(), out StatusCode))
                            {
                                job1.Status = StatusCode;
                            }
                            else
                            {
                                job1.Status = 0;
                            }
                            var placeList = new PlaceViewModel();
                            placeList.PlaceList = new List <PlaceModel>();
                            var appPlace = new List <Place>();
                            DropdownValues();
                            appPlace = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();

                            placeList.PlaceList.Add(new PlaceModel
                            {
                                PlaceGUID        = Guid.Empty.ToString(),
                                PlaceName        = "All",
                                UserGUID         = "",
                                OrganizationGUID = "",
                            });

                            foreach (var place in appPlace.ToList())
                            {
                                placeList.PlaceList.Add(new PlaceModel
                                {
                                    PlaceGUID        = place.PlaceGUID.ToString(),
                                    PlaceID          = place.PlaceID,
                                    PlaceName        = place.PlaceName,
                                    UserGUID         = place.UserGUID.ToString(),
                                    OrganizationGUID = place.OrganizationGUID != null ? place.OrganizationGUID.ToString() : Guid.Empty.ToString(),
                                });
                            }

                            var marketList = new MarketViewModel();
                            marketList.MarketList = new List <MarketModel>();
                            var appMarket = new List <Market>();
                            //if (Session["UserType"].ToString() == "ENT_A")
                            {
                                appMarket = _IMarketRepository.GetMarketByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), 1).ToList();
                            }
                            //else
                            //{
                            //    appMarket = _IMarketRepository.GetMarketByUserGUID(new Guid(Session["UserGUID"].ToString()), 1).ToList();
                            //}

                            foreach (var market in appMarket.ToList())
                            {
                                marketList.MarketList.Add(new MarketModel
                                {
                                    MarketGUID         = market.MarketGUID.ToString(),
                                    UserGUID           = market.UserGUID != null ? market.UserGUID.ToString() : Guid.Empty.ToString(),
                                    OrganizationGUID   = market.OrganizationGUID != null ? market.OrganizationGUID.ToString() : Guid.Empty.ToString(),
                                    OwnerGUID          = market.OwnerGUID != null ? market.OwnerGUID.ToString() : Guid.Empty.ToString(),
                                    MarketName         = market.MarketName,
                                    MarketPhone        = market.MarketPhone,
                                    PrimaryContactGUID = market.PrimaryContactGUID != null ? market.PrimaryContactGUID.ToString() : Guid.Empty.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 != null ? market.RegionGUID.ToString() : Guid.Empty.ToString(),
                                    TerritoryGUID = market.TerritoryGUID != null ? market.TerritoryGUID.ToString() : Guid.Empty.ToString(),
                                    RegionName    = market.RegionGUID != null ? _IRegionRepository.GetRegionNameByRegionGUID(new Guid(market.RegionGUID.ToString())) : "",
                                    TerritoryName = market.TerritoryGUID != null ? _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(market.TerritoryGUID.ToString())) : "",
                                });
                            }
                            pJobProgressViewModel = getJobProgress(_job.JobModel.JobIndexGUID.ToString());
                            var viewModel = new JobViewModel();
                            viewModel.Place           = placeList.PlaceList;
                            viewModel.Market          = marketList.MarketList;
                            viewModel.JobProgressList = pJobProgressViewModel;
                            viewModel.JobModel        = job1;

                            return(View("Index", viewModel));
                        }
                        else
                        {
                            return(RedirectToAction("../User/Login"));
                        }
                    }
                }
                else
                {
                    return(RedirectToAction("SessionTimeOut", "User"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(RedirectToAction("Login", "User"));
            }
        }
Ejemplo n.º 3
0
        //
        // GET: /JobStatus/
        public ActionResult Index(string FromDate = "", string ToDate = "", string regionguid = "", string territoryguid = "", string jobindexguid = "", string Date = "", string selection = "", string ponumber = "")
        {
            Logger.Debug("Inside AssignJob Controller- Index");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(Date))
                    {
                        ViewBag.DateValue = HttpUtility.HtmlDecode(Date);
                    }
                    var jobStatus = new JobStatusViewModel();
                    jobStatus.JobStatusModel = new List <JobStatusModel>();
                    var jobGroup = new List <Job>();
                    //Job ljob = new Job();

                    OrganizationUsersMap pOrganizationUsersMap = _IUserRepository.GetUserByID(new Guid(Session["UserGUID"].ToString()));
                    Logger.Debug("USerGUID:" + Session["UserGUID"].ToString());
                    if (pOrganizationUsersMap != null)
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<div class='actions'>");
                        sb.Append("<div class='btn-group'>");
                        if (!string.IsNullOrEmpty(territoryguid))
                        {
                            Logger.Debug("Inside TerritoryGUID" + territoryguid.ToString());
                            sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> " + _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(territoryguid)) + " <i class='icon-angle-down'></i></a>");
                        }
                        else
                        {
                            if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_U")
                            {
                                if (!string.IsNullOrEmpty(selection) && selection == "All")
                                {
                                    sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> All <i class='icon-angle-down'></i></a>");
                                }
                                else
                                {
                                    sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> Select Market <i class='icon-angle-down'></i></a>");
                                }
                            }
                            else if (pOrganizationUsersMap != null)
                            {
                                sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> " + _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(pOrganizationUsersMap.TerritoryGUID.ToString())) + " <i class='icon-angle-down'></i></a>");
                            }
                        }
                        sb.Append("<ul id='ulworkgroup' class='dropdown-menu pull-right'>");

                        if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_U" && pOrganizationUsersMap != null)
                        {
                            if (string.IsNullOrEmpty(selection) || selection != "All")
                            {
                                sb.Append("<li><a href=" + Url.Action("Index", "JobStatus", new { selection = "All" }) + ">All</a></li>");
                            }
                            List <Territory> TerritoryList = new List <Territory>();
                            if (Session["UserType"].ToString() == "ENT_A")
                            {
                                Logger.Debug("Inside OrganizationGUID" + pOrganizationUsersMap.OrganizationGUID.ToString());
                                TerritoryList = _ITerritoryRepository.GetTerritoryByOrganizationGUID(new Guid(pOrganizationUsersMap.OrganizationGUID.ToString())).ToList();
                            }
                            else
                            {
                                if (pOrganizationUsersMap.RegionGUID != null)
                                {
                                    Logger.Debug("Inside RegionGUID" + pOrganizationUsersMap.RegionGUID.ToString());
                                    TerritoryList = _ITerritoryRepository.GetTerritoryByRegionGUID(new Guid(pOrganizationUsersMap.RegionGUID.ToString())).ToList();
                                }
                            }
                            if (TerritoryList != null && TerritoryList.Count > 0)
                            {
                                foreach (Territory item in TerritoryList)
                                {
                                    sb.Append("<li><a href=" + Url.Action("Index", "JobStatus", new { territoryguid = item.TerritoryGUID.ToString(), regionguid = item.RegionGUID.ToString() }) + " data-groupguid=" + item.TerritoryGUID + ">" + item.Name + "</a></li>");
                                    Logger.Debug("Inside Territory foreach");
                                }
                            }
                        }
                        sb.Append("</ul>");
                        sb.Append("</div>");
                        sb.Append("</div>");

                        ViewBag.RegionList = sb.ToString();
                        Job mjob = new Job();
                        if (!string.IsNullOrEmpty(ponumber))
                        {
                            mjob.PONumber        = ponumber;
                            TempData["PoNumber"] = ponumber;
                        }
                        if (!string.IsNullOrEmpty(FromDate) && !string.IsNullOrEmpty(ToDate))
                        {
                            //ViewBag.FromDate = FromDate;
                            //ViewBag.ToDate = ToDate;
                            if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_U")
                            {
                                mjob.ActualStartTime = Convert.ToDateTime(FromDate);
                                // mjob.PreferedStartTime = _IUserRepository.GetLocalDateTime(mjob.PreferedStartTime, Session["TimeZoneID"].ToString());
                                mjob.ActualEndTime = Convert.ToDateTime(ToDate);
                                //  mjob.PreferedEndTime = _IUserRepository.GetLocalDateTime(mjob.PreferedEndTime, Session["TimeZoneID"].ToString());
                                mjob.TerritoryGUID    = pOrganizationUsersMap.TerritoryGUID;
                                mjob.RegionGUID       = pOrganizationUsersMap.RegionGUID;
                                mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                                jobGroup = _IJobRepository.GetJobs(mjob);
                            }
                            else
                            {
                                mjob.ActualStartTime = Convert.ToDateTime(FromDate);
                                //   mjob.PreferedStartTime = _IUserRepository.GetLocalDateTime(mjob.PreferedStartTime, Session["TimeZoneID"].ToString());
                                mjob.ActualEndTime = Convert.ToDateTime(ToDate);
                                //    mjob.PreferedEndTime = _IUserRepository.GetLocalDateTime(mjob.PreferedEndTime, Session["TimeZoneID"].ToString());
                                mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                                jobGroup = _IJobRepository.GetJobs(mjob);
                            }
                        }
                        else if (!string.IsNullOrEmpty(regionguid) && !string.IsNullOrEmpty(territoryguid))
                        {
                            mjob.ActualStartTime  = DateTime.Now.AddDays(-29);
                            mjob.ActualEndTime    = DateTime.Now;
                            mjob.RegionGUID       = new Guid(regionguid);
                            mjob.TerritoryGUID    = new Guid(territoryguid);
                            mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                            jobGroup = _IJobRepository.GetJobs(mjob);
                        }
                        else
                        {
                            mjob.ActualStartTime = DateTime.Now.AddDays(-29);
                            mjob.ActualEndTime   = DateTime.Now;
                            if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_U")
                            {
                                mjob.RegionGUID       = pOrganizationUsersMap.RegionGUID;
                                mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                                jobGroup = _IJobRepository.GetJobs(mjob);
                            }
                            else
                            {
                                mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                                jobGroup = _IJobRepository.GetJobs(mjob);
                            }
                            //if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_U")
                            //{
                            //    jobGroup = _IJobRepository.GetjobStatusByRegionAndTerritory(new Guid(Session["UserGUID"].ToString())).ToList();
                            //}
                            //else
                            //{
                            //    ljob.AssignedUserGUID = new Guid(Session["UserGUID"].ToString());
                            //    ljob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                            //    ljob.IsDeleted = false;
                            //    jobGroup = _IJobRepository.GetJobStatus(ljob).ToList();
                            //}
                        }

                        if (jobGroup != null && jobGroup.Count > 0)
                        {
                            foreach (var job in jobGroup.ToList())
                            {
                                JobStatusModel js = new JobStatusModel();
                                js.JobName      = job.JobName;
                                js.JobIndexGUID = job.JobGUID.ToString();
                                //  js.JobLogicalID = job.JobFormGUID.ToString();
                                js.UserGUID = job.AssignedUserGUID.ToString();

                                js.PreferredStartTime = job.PreferedStartTime != null ? Session["TimeZoneID"] != null?_IUserRepository.GetLocalDateTime(job.PreferedStartTime, Session["TimeZoneID"].ToString()) : job.PreferedStartTime.ToString() : "";

                                js.PreferredStartTime = !string.IsNullOrEmpty(js.PreferredStartTime) ? _IUserRepository.GetLocalDateTime(job.PreferedStartTime, Session["TimeZoneID"].ToString()) : "";
                                js.PreferredStartTime = !string.IsNullOrEmpty(js.PreferredStartTime) ? Convert.ToDateTime(js.PreferredStartTime).ToString("MM/dd/yy HH:mm") : "";

                                js.PreferredEndTime = job.PreferedEndTime != null ? Session["TimeZoneID"] != null?_IUserRepository.GetLocalDateTime(job.PreferedEndTime, Session["TimeZoneID"].ToString()) : job.PreferedEndTime.ToString() : "";

                                js.PreferredEndTime = !string.IsNullOrEmpty(js.PreferredEndTime) ? _IUserRepository.GetLocalDateTime(job.PreferedEndTime, Session["TimeZoneID"].ToString()) : "";
                                js.PreferredEndTime = !string.IsNullOrEmpty(js.PreferredEndTime) ? Convert.ToDateTime(js.PreferredEndTime).ToString("MM/dd/yy HH:mm") : "";

                                js.ActualStartTime = job.ActualStartTime != null ? Session["TimeZoneID"] != null?_IUserRepository.GetLocalDateTime(job.ActualStartTime, Session["TimeZoneID"].ToString()) : job.ActualStartTime.ToString() : "";

                                js.ActualStartTime = !string.IsNullOrEmpty(js.ActualStartTime) ? _IUserRepository.GetLocalDateTime(job.ActualStartTime, Session["TimeZoneID"].ToString()) : "";
                                js.ActualStartTime = !string.IsNullOrEmpty(js.ActualStartTime) ? Convert.ToDateTime(js.ActualStartTime).ToString("MM/dd/yy HH:mm") : "";

                                js.ActualEndTime = job.PreferedEndTime != null ? Session["TimeZoneID"] != null?_IUserRepository.GetLocalDateTime(job.ActualEndTime, Session["TimeZoneID"].ToString()) : job.ActualEndTime.ToString() : "";

                                js.ActualEndTime = !string.IsNullOrEmpty(js.ActualEndTime) ? _IUserRepository.GetLocalDateTime(job.ActualEndTime, Session["TimeZoneID"].ToString()) : "";
                                js.ActualEndTime = !string.IsNullOrEmpty(js.ActualEndTime) ? Convert.ToDateTime(js.ActualEndTime).ToString("MM/dd/yy HH:mm") : "";


                                js.LastModifiedDate = job.PreferedEndTime != null ? Session["TimeZoneID"] != null?_IUserRepository.GetLocalDateTime(job.LastModifiedDate, Session["TimeZoneID"].ToString()) : job.LastModifiedDate.ToString() : "";

                                js.LastModifiedDate = !string.IsNullOrEmpty(js.LastModifiedDate) ? _IUserRepository.GetLocalDateTime(job.LastModifiedDate, Session["TimeZoneID"].ToString()) : "";
                                js.LastModifiedDate = !string.IsNullOrEmpty(js.LastModifiedDate) ? Convert.ToDateTime(js.LastModifiedDate).ToString("MM/dd/yy HH:mm") : "";



                                //  ActualStartTime = job.ActualStartTime.ToString() != "" ? Convert.ToDateTime(job.ActualStartTime).ToString("yyyy/MM/dd HH:mm") : "",//, Session["TimeZoneID"].ToString()
                                js.EstimatedStartTime = job.ActualStartTime != null ? Session["TimeZoneID"] != null?_IUserRepository.GetLocalDateTime(job.ActualStartTime, Session["TimeZoneID"].ToString()) : job.ActualStartTime.ToString() : "";

                                js.EstimatedStartTime = !string.IsNullOrEmpty(js.EstimatedStartTime) ? _IUserRepository.GetLocalDateTime(job.ActualStartTime, Session["TimeZoneID"].ToString()) : "";
                                js.EstimatedStartTime = !string.IsNullOrEmpty(js.EstimatedStartTime) ? Convert.ToDateTime(js.EstimatedStartTime).ToString("MM/dd/yy HH:mm") : "";
                                //js.AssignedTo = _IGlobalUserRepository.GetGlobalUserByID(new Guid(job.AssignedUserGUID.ToString())) != null ? _IGlobalUserRepository.GetGlobalUserByID(new Guid(job.AssignedUserGUID.ToString())).UserName : "";
                                js.EstimatedDuration = Convert.ToDouble(job.EstimatedDuration);
                                js.Status            = _IJobRepository.GetStatusName(Convert.ToInt32(job.StatusCode));
                                // js.CustomerName = !string.IsNullOrEmpty(job.CustomerGUID.ToString()) ? GetCompanyName(new Guid(job.CustomerGUID.ToString())) : "";
                                js.CustomerName = job.CustomerGUID != null?GetCompanyName(job.CustomerGUID) : GetCompanyNameByPO(job.PONumber);

                                js.StoreID    = !string.IsNullOrEmpty(job.CustomerGUID.ToString()) ? getStoreID(job.CustomerStopGUID.ToString()) : "";
                                js.PONumber   = job.PONumber;
                                js.statuscode = job.StatusCode != null?Convert.ToInt32(job.StatusCode) : 0;

                                js.RegionGUID = job.RegionGUID != null?job.RegionGUID.ToString() : "";

                                js.TerritoryGUID = job.TerritoryGUID != null?job.TerritoryGUID.ToString() : "";

                                js.SiteAddress = job.ServiceAddress;
                                JobProgress pJobProgress = _IJobRepository.GetJobProgressMismatch(job.JobGUID, js.statuscode);
                                bool        mismatch;
                                if (pJobProgress != null && bool.TryParse(pJobProgress.LocationMismatch.ToString(), out mismatch))
                                {
                                    js.locationmismatch = mismatch;
                                }
                                if (job.StatusCode >= 2 && job.AssignedUserGUID != null)
                                {
                                    js.Email = GetEmails(new Guid(job.AssignedUserGUID.ToString()), pOrganizationUsersMap.OrganizationGUID);
                                    js.AssociateContactNumber = GetContactNumber(new Guid(job.AssignedUserGUID.ToString()), pOrganizationUsersMap.OrganizationGUID);
                                    GlobalUser _globaluser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(job.AssignedUserGUID.ToString()));
                                    if (_globaluser != null)
                                    {
                                        js.AssociateName = _globaluser.UserName;
                                        js.AssignedTo    = _globaluser.UserName;
                                    }
                                    else
                                    {
                                        js.AssignedTo    = "";
                                        js.AssociateName = "";
                                    }
                                }
                                else
                                {
                                    js.Email                  = "";
                                    js.AssignedTo             = "";
                                    js.AssociateName          = "";
                                    js.AssociateContactNumber = "";
                                }
                                //js.GroupName = _IJobRepository.GetGroupName(job.GroupCode);



                                if (job.CustomerStopGUID != null && job.CustomerStopGUID != Guid.Empty)
                                {
                                    Market _Market = _IMarketRepository.GetMarketByID(new Guid(job.CustomerStopGUID.ToString()));
                                    if (_Market != null)
                                    {
                                        if (!string.IsNullOrEmpty(_Market.RMUserID))
                                        {
                                            GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(_Market.RMUserID, Session["OrganizationGUID"].ToString());
                                            if (_globalUser != null)
                                            {
                                                UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, job.OrganizationGUID);
                                                if (_userprofile != null)
                                                {
                                                    js.RegionalManager = _userprofile.FirstName + " " + _userprofile.LastName;
                                                }
                                                else
                                                {
                                                    js.RegionalManager = "";
                                                }
                                            }
                                        }
                                        else
                                        {
                                            js.RegionalManager = "";
                                        }
                                        if (!string.IsNullOrEmpty(_Market.FMUserID))
                                        {
                                            GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(_Market.FMUserID, Session["OrganizationGUID"].ToString());
                                            if (_globalUser != null)
                                            {
                                                UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, pOrganizationUsersMap.OrganizationGUID);
                                                if (_userprofile != null)
                                                {
                                                    js.FieldManager = _userprofile.FirstName + " " + _userprofile.LastName;
                                                }
                                                else
                                                {
                                                    js.FieldManager = "";
                                                }
                                            }
                                        }
                                        else
                                        {
                                            js.FieldManager = "";
                                        }
                                    }
                                    else
                                    {
                                        js.RegionalManager = "";
                                        js.FieldManager    = "";
                                    }
                                }
                                else if (!string.IsNullOrEmpty(job.PONumber))
                                {
                                    POs _po = _IPORepository.GetPObyPoNumber(job.PONumber);
                                    if (_po != null)
                                    {
                                        Market _Market = _IMarketRepository.GetMarketByCustomerID(job.OrganizationGUID, _po.PlaceID, _po.MarketID);
                                        if (_Market != null)
                                        {
                                            if (!string.IsNullOrEmpty(_Market.RMUserID))
                                            {
                                                GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(_Market.RMUserID, Session["OrganizationGUID"].ToString());
                                                if (_globalUser != null)
                                                {
                                                    UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, job.OrganizationGUID);
                                                    if (_userprofile != null)
                                                    {
                                                        js.RegionalManager = _userprofile.FirstName + " " + _userprofile.LastName;
                                                    }
                                                    else
                                                    {
                                                        js.RegionalManager = "";
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                js.RegionalManager = "";
                                            }
                                            if (!string.IsNullOrEmpty(_Market.FMUserID))
                                            {
                                                GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(_Market.FMUserID, Session["OrganizationGUID"].ToString());
                                                if (_globalUser != null)
                                                {
                                                    UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, job.OrganizationGUID);
                                                    if (_userprofile != null)
                                                    {
                                                        js.FieldManager = _userprofile.FirstName + " " + _userprofile.LastName;
                                                    }
                                                    else
                                                    {
                                                        js.FieldManager = "";
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                js.FieldManager = "";
                                            }
                                        }
                                        else
                                        {
                                            js.RegionalManager = "";
                                            js.FieldManager    = "";
                                        }
                                    }
                                    else
                                    {
                                        js.RegionalManager = "";
                                        js.FieldManager    = "";
                                    }
                                }
                                else
                                {
                                    js.RegionalManager = "";
                                    js.FieldManager    = "";
                                }

                                jobStatus.JobStatusModel.Add(js);
                            }
                        }
                        if (!string.IsNullOrEmpty(regionguid) && !string.IsNullOrEmpty(territoryguid) && !string.IsNullOrEmpty(jobindexguid))
                        {
                            IList <GlobalUser> _GlobalUser = _IGlobalUserRepository.GetGlobalUserByRegionandTerritory(new Guid(regionguid), new Guid(territoryguid)).ToList();
                            jobStatus.GlobalUsers = new List <GlobalUserModel>();
                            foreach (var user in _GlobalUser.ToList())
                            {
                                jobStatus.GlobalUsers.Add(new GlobalUserModel
                                {
                                    UserGUID = user.UserGUID,
                                    UserName = user.UserName
                                });
                            }

                            if (!string.IsNullOrEmpty(jobindexguid))
                            {
                                jobStatus.JobModel              = new JobModel();
                                jobStatus.JobModel.JobName      = _IJobRepository.GetJobByID(new Guid(jobindexguid)).JobName;
                                jobStatus.JobModel.JobIndexGUID = new Guid(jobindexguid);
                            }
                        }
                    }



                    return(View(jobStatus));
                }
                else
                {
                    //TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Session Expired');</script>";
                    //return RedirectToAction("../User/Login");
                    return(RedirectToAction("SessionTimeOut", "User"));
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(RedirectToAction("Login", "User"));
            }
        }