예제 #1
0
        public ActionResult Index(string FromDate = "", string ToDate = "")
        {
            Logger.Debug("Inside Job Controller- Index");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    var jobList = new JobViewModel();
                    jobList.JobModelList = new List<JobModel>();
                    var jobGroup = new List<Job>();
                    Job ljob = new Job();
                    if (!string.IsNullOrEmpty(FromDate) && !string.IsNullOrEmpty(ToDate))
                    {
                        ViewBag.FromDate = FromDate;
                        ViewBag.ToDate = ToDate;
                        jobGroup = _IJobRepository.GetjobByOrganizationGUIDBetweenDate(new Guid(Session["OrganizationGUID"].ToString()), Convert.ToDateTime(FromDate), Convert.ToDateTime(ToDate)).ToList();
                    }
                    else
                    {
                        ljob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString());
                        ljob.IsDeleted = false;
                        jobGroup = _IJobRepository.GetOpenJobs(ljob).ToList();
                    }

                    foreach (var job in jobGroup.ToList())
                    {
                        jobList.JobModelList.Add(new JobModel
                        {
                            JobName = job.JobName,
                            JobIndexGUID = job.JobGUID,
                            //  JobLogicalID = new Guid(job.JobFormGUID.ToString()),
                            PreferredEndTime = Convert.ToDateTime(job.PreferedEndTime).ToString("yy/MM/dd HH:mm"),
                            PreferredStartTime = Convert.ToDateTime(job.PreferedStartTime).ToString("yy/MM/dd HH:mm"),
                            CustomerName = _IJobRepository.GetCustomerName(new Guid(job.CustomerGUID.ToString())),
                            GroupName = "",
                            CustomerPointName = _IJobRepository.GetCustomerPointName(new Guid(job.CustomerStopGUID.ToString()))
                        });
                    }

                    return View(jobList.JobModelList.AsEnumerable());
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return RedirectToAction("Login", "User");
            }
        }
        // GET: /JobDetails/
        public ActionResult Index(string id = "", string marketguid = "", string jobindexguid = "")
        {
            Logger.Debug("Inside People Controller- Create");
            try
            {

                if (Session["OrganizationGUID"] != null)
                {
                    if (!string.IsNullOrEmpty(jobindexguid))
                    {
                        if (!string.IsNullOrEmpty(id))
                        {
                            TempData["TabName"] = id;
                        }
                        else
                        {
                            TempData["TabName"] = "Details";
                        }
                        DropdownValues();
                        Job _job = _IJobRepository.GetJobByID(new Guid(jobindexguid));

                        JobModel job = new JobModel();
                        job.JobIndexGUID = _job.JobGUID;
                        //   job.JobLogicalID = _IJobSchemaRepository.GetJobFormIDfromJobForm(_job.JobForm.ToString());
                        job.JobReferenceNo = _job.JobReferenceNo;
                        job.JobName = _job.JobName;
                        if (_job.CustomerGUID != null && !string.IsNullOrEmpty(_job.CustomerGUID.ToString()))
                        {
                            job.CustGUID = new Guid(_job.CustomerGUID.ToString());
                        }
                        else
                        {
                            job.CustGUID = Guid.Empty;
                        }
                        job.IsScheduled = _job.IsSecheduled == true ? "true" : "false";

                        double duration;
                        if (double.TryParse(_job.EstimatedDuration.ToString(), out duration))
                        {
                            TimeSpan time = new TimeSpan();
                            time = TimeSpan.FromSeconds(duration);
                            //timeformat = time.Hours + " : " + time.Minutes + " : " + time.Seconds;
                            job.Duration = time.Hours + " : " + time.Minutes;
                            job.EstimatedDuration = duration;
                            //job.EstimatedDuration = duration / 3600;
                        }
                        else
                        {
                            job.EstimatedDuration = 0;
                        }
                        job.PreferredStartTime = _job.PreferedStartTime != null ? Session["TimeZoneID"] != null ? _IUserRepository.GetLocalDateTime(_job.PreferedStartTime, Session["TimeZoneID"].ToString()) : _job.PreferedStartTime.ToString() : "";
                        job.PreferredStartTime = !string.IsNullOrEmpty(job.PreferredStartTime) ? _IUserRepository.GetLocalDateTime(_job.PreferedStartTime, Session["TimeZoneID"].ToString()) : "";
                        job.PreferredStartTime = !string.IsNullOrEmpty(job.PreferredStartTime) ? Convert.ToDateTime(job.PreferredStartTime).ToString("MM/dd/yy HH:mm") : "";


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

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

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


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

                        //job.PreferredEndTime = Convert.ToDateTime(_job.PreferedEndTime).ToString("yyyy/MM/dd HH:mm");

                        if (_job.RegionGUID != null)
                            job.RegionCode = new Guid(_job.RegionGUID.ToString());
                        else
                            job.RegionCode = Guid.Empty;
                        if (_job.TerritoryGUID != null)
                            job.TerritoryCode = new Guid(_job.TerritoryGUID.ToString());
                        else
                            job.TerritoryCode = Guid.Empty;
                        if (_job.CustomerStopGUID != null && !string.IsNullOrEmpty(_job.CustomerStopGUID.ToString()))
                        {
                            job.StopsGUID = new Guid(_job.CustomerStopGUID.ToString());
                        }
                        else
                        {
                            job.StopsGUID = Guid.Empty;
                        }
                        job.CustomerName = job.CustGUID != Guid.Empty ? _IJobRepository.GetCustomerName(job.CustGUID) : "";
                        job.CreateDate = _job.CreateDate;
                        int StatusCode; ;
                        if (int.TryParse(_job.StatusCode.ToString(), out StatusCode))
                        {
                            job.Status = StatusCode;
                        }
                        else
                        {
                            job.Status = 0;
                        }

                        var placeList = new PlaceViewModel();
                        placeList.PlaceList = new List<PlaceModel>();
                        var appPlace = new List<Place>();

                        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.ToString(),
                            });
                        }

                        var marketList = new MarketViewModel();
                        marketList.MarketList = new List<MarketModel>();
                        var appMarket = new List<Market>();
                        if (string.IsNullOrEmpty(marketguid) || Guid.Empty == new Guid(marketguid))
                        {
                            // 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();
                            //}
                            if (!string.IsNullOrEmpty(marketguid) && Guid.Empty == new Guid(marketguid))
                                ViewBag.PlaceGUID = Guid.Empty.ToString();
                        }
                        else
                        {
                            appMarket = _IMarketRepository.GetMarketByOwnerGUID(new Guid(marketguid)).ToList();
                            ViewBag.PlaceGUID = marketguid;
                        }
                        foreach (var market in appMarket.ToList())
                        {
                            marketList.MarketList.Add(new MarketModel
                            {
                                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 != 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())) : "",
                            });
                        }
                        List<JobProgressViewModel> pJobProgressViewModel = new List<JobProgressViewModel>();
                        pJobProgressViewModel = getJobProgress(jobindexguid);
                        var viewModel = new JobViewModel();
                        viewModel.Place = placeList.PlaceList;
                        viewModel.Market = marketList.MarketList;
                        viewModel.JobModel = job;
                        viewModel.JobProgressList = pJobProgressViewModel;
                        return View(viewModel);
                    }
                    else
                    {
                        return RedirectToAction("Index", "JobDetails", new { id = "Details" });
                    }
                }
                else
                {
                    return RedirectToAction("SessionTimeOut", "User");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return RedirectToAction("Login", "User");
            }

        }
        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");
            }
        }
예제 #4
0
        public ActionResult Edit(string id = "", string jobindexguid = "")
        {
            Logger.Debug("Inside People Controller- Create");
            try
            {

                if (Session["OrganizationGUID"] != null)
                {
                    DropdownValues();
                    Job _job = _IJobRepository.GetJobByID(new Guid(jobindexguid));
                    JobModel job = new JobModel();
                    job.JobIndexGUID = _job.JobGUID;
                    //   job.JobLogicalID = _IJobSchemaRepository.GetJobFormIDfromJobForm(_job.JobForm.ToString());
                    job.JobReferenceNo = _job.JobReferenceNo;
                    job.JobName = _job.JobName;
                    job.CustGUID = _job.CustomerGUID != null ? new Guid(_job.CustomerGUID.ToString()) : Guid.Empty;
                    job.IsScheduled = _job.IsSecheduled == true ? "true" : "false";

                    double duration;
                    if (double.TryParse(_job.EstimatedDuration.ToString(), out duration))
                        job.EstimatedDuration = duration / 3600;
                    else
                        job.EstimatedDuration = 0;

                    job.PreferredStartTime = Convert.ToDateTime(_job.PreferedStartTime).ToString("yy/MM/dd HH:mm");
                    job.PreferredEndTime = Convert.ToDateTime(_job.PreferedEndTime).ToString("yy/MM/dd HH:mm");
                    job.RegionCode = _job.RegionGUID != null ? new Guid(_job.RegionGUID.ToString()) : Guid.Empty;
                    job.TerritoryCode = _job.TerritoryGUID != null ? new Guid(_job.TerritoryGUID.ToString()) : Guid.Empty;
                    job.StopsGUID = _job.CustomerStopGUID != null ? new Guid(_job.CustomerStopGUID.ToString()) : Guid.Empty;
                    job.CustomerName = job.CustGUID != Guid.Empty ? _IJobRepository.GetCustomerName(job.CustGUID) : "";
                    job.CreateDate = _job.CreateDate;

                    var placeList = new PlaceViewModel();
                    placeList.PlaceList = new List<PlaceModel>();
                    var appPlace = new List<Place>();

                    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 (string.IsNullOrEmpty(id) || Guid.Empty == new Guid(id))
                    {
                        // 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();
                        //}
                        if (!string.IsNullOrEmpty(id) && Guid.Empty == new Guid(id))
                            ViewBag.PlaceGUID = Guid.Empty.ToString();
                    }
                    else
                    {
                        appMarket = _IMarketRepository.GetMarketByOwnerGUID(new Guid(id)).ToList();
                        ViewBag.PlaceGUID = id;
                    }
                    foreach (var market in appMarket.ToList())
                    {
                        marketList.MarketList.Add(new MarketModel
                        {
                            MarketGUID = market.MarketGUID.ToString(),
                            MarketID = market.MarketID,
                            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())) : "",
                        });
                    }

                    var viewModel = new JobViewModel();
                    viewModel.Place = placeList.PlaceList;
                    viewModel.Market = marketList.MarketList;
                    viewModel.JobModel = job;

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

        }
예제 #5
0
        public ActionResult Create(string id = "")
        {
            Logger.Debug("Inside People Controller- Create");
            try
            {

                if (Session["OrganizationGUID"] != null)
                {
                    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 (string.IsNullOrEmpty(id) || Guid.Empty == new Guid(id))
                    {
                        // 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();
                        //}
                        if (!string.IsNullOrEmpty(id) && Guid.Empty == new Guid(id))
                            ViewBag.PlaceGUID = Guid.Empty.ToString();
                    }
                    else
                    {
                        appMarket = _IMarketRepository.GetMarketByOwnerGUID(new Guid(id)).ToList();
                        ViewBag.PlaceGUID = id;
                    }
                    foreach (var market in appMarket.ToList())
                    {
                        marketList.MarketList.Add(new MarketModel
                        {
                            MarketGUID = market.MarketGUID.ToString(),
                            MarketID = market.MarketID,
                            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())) : "",
                        });
                    }

                    var viewModel = new JobViewModel();
                    viewModel.Place = placeList.PlaceList;
                    viewModel.Market = marketList.MarketList;
                    if (TempData["JobItem"] != null)
                    {
                        viewModel.JobModel = (JobModel)TempData["JobItem"];
                    }

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

        }
        //
        // GET: /AssignJob/
        public ActionResult Index(string regionguid = "", string territoryguid = "", string jobindexguid = "", string groupguid = "", string territoryid = "")
        {
            Logger.Debug("Inside Job Controller- Index");
            try
            {
                if (Session["OrganizationGUID"] != null)
                {
                    var jobList = new JobViewModel();
                    jobList.JobModelList = new List<JobModel>();
                    var jobGroup = new List<Job>();
                    Job ljob = new Job();
                    if (!string.IsNullOrEmpty(groupguid))
                    {
                        jobGroup = _IJobRepository.GetjobByGroupGUID(new Guid(groupguid)).ToList();
                    }
                    else if (!string.IsNullOrEmpty(territoryid))
                    {
                        ljob.TerritoryGUID = new Guid(territoryid);
                        ljob.IsDeleted = false;
                        jobGroup = _IJobRepository.GetOpenJobs(ljob).ToList();
                    }
                    else
                    {
                        jobGroup = _IJobRepository.GetjobByRegionandTerritory(new Guid(Session["UserGUID"].ToString())).ToList();
                    }
                    foreach (var job in jobGroup.ToList())
                    {
                        jobList.JobModelList.Add(new JobModel
                        {
                            JobName = job.JobName,
                            JobIndexGUID = job.JobGUID,
                            //  JobLogicalID = new Guid(job.JobFormGUID.ToString()),
                            PreferredEndTime = Convert.ToDateTime(job.PreferedEndTime).ToString("yy/MM/dd HH:mm"),
                            PreferredStartTime = Convert.ToDateTime(job.PreferedStartTime).ToString("yy/MM/dd HH:mm"),
                            RegionCode = job.RegionGUID != null ? new Guid(job.RegionGUID.ToString()) : Guid.Empty,
                            TerritoryCode = job.TerritoryGUID != null ? new Guid(job.TerritoryGUID.ToString()) : Guid.Empty,
                        });
                    }
                    var viewmodel = new AssignJobModel();
                    if (string.IsNullOrEmpty(regionguid) && string.IsNullOrEmpty(territoryguid) && string.IsNullOrEmpty(jobindexguid))
                    {
                        viewmodel.GlobalUsers = null;
                        viewmodel.JobModel = null;
                        viewmodel.JobModelList = jobList.JobModelList;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(regionguid) && !string.IsNullOrEmpty(territoryguid))
                        {
                            IList<GlobalUser> _GlobalUser = _IGlobalUserRepository.GetGlobalUserByRegionandTerritory(new Guid(regionguid), new Guid(territoryguid)).ToList();
                            viewmodel.GlobalUsers = new List<GlobalUserModel>();
                            foreach (var user in _GlobalUser.ToList())
                            {
                                viewmodel.GlobalUsers.Add(new GlobalUserModel
                                {
                                    UserGUID = user.UserGUID,
                                    UserName = user.UserName
                                });
                            }
                        }
                        if (!string.IsNullOrEmpty(jobindexguid))
                        {
                            viewmodel.JobModel = new JobModel();
                            viewmodel.JobModel.JobName = _IJobRepository.GetJobByID(new Guid(jobindexguid)).JobName;
                            viewmodel.JobModel.JobIndexGUID = new Guid(jobindexguid);
                        }
                        viewmodel.JobModelList = jobList.JobModelList;
                    }

                    StringBuilder sb = new StringBuilder();
                    sb.Append("<div class='actions'>");
                    sb.Append("<div class='btn-group'>");
                    if (!string.IsNullOrEmpty(territoryid))
                    {
                        sb.Append("<a href='#' id='ulaterritorygroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(new Guid(territoryid)) + " <i class='icon-angle-down'></i></a>");
                    }
                    else
                    {
                        sb.Append("<a href='#' id='ulaterritorygroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>Zone <i class='icon-angle-down'></i></a>");
                    }
                    sb.Append("<ul id='ulterritorygroup' class='dropdown-menu pull-left'>");
                    sb.Append("<li><a href=" + Url.Action("Index", new { id = "" }) + ">All</a></li>");
                    List<Territory> TerritoryList = _ITerritoryRepository.GetTerritoryByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                    foreach (Territory item in TerritoryList)
                    {
                        sb.Append("<li><a href=" + Url.Action("Index", new { territoryid = item.TerritoryGUID.ToString() }) + " data-groupguid=" + item.TerritoryGUID + ">" + item.Name + "</a></li>");
                    }
                    sb.Append("</ul>");
                    sb.Append("</div>");
                    sb.Append("</div>");
                    ViewBag.ZoneList = sb.ToString();

                    StringBuilder sb1 = new StringBuilder();
                    sb1.Append("<div class='actions'>");
                    sb1.Append("<div class='btn-group'>");
                    //if (!string.IsNullOrEmpty(groupguid))
                    //{
                    //    sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + _IGroupRepository.GetGroupNameByGroupGUID(new Guid(groupguid)) + " <i class='icon-angle-down'></i></a>");
                    //}
                    //else
                    {
                        sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>Worker Group <i class='icon-angle-down'></i></a>");
                    }
                    sb1.Append("<ul id='ulworkergroup' class='dropdown-menu pull-left'>");
                    sb1.Append("<li><a href=" + Url.Action("Index", new { id = "" }) + ">All</a></li>");
                    //List<Group> GroupList = _IGroupRepository.GetGroupByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList();
                    //foreach (Group item in GroupList)
                    //{
                    //    sb1.Append("<li><a href=" + Url.Action("Index", new { groupguid = item.GroupGUID.ToString() }) + " data-groupguid=" + item.GroupGUID + ">" + item.Name + "</a></li>");
                    //}
                    sb1.Append("</ul>");
                    sb1.Append("</div>");
                    sb1.Append("</div>");
                    ViewBag.GroupList = sb1.ToString();

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

            }
        }