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: /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"); } }
private StoreVisit ConvertToStoreVisit(Job job) { try { DateTime Datecontent, Datecontent1, Datecontent2; StoreVisit _store = new StoreVisit(); _store.JobGUID = job.JobGUID; _store.JobName = job.JobName; _store.PONumber = job.PONumber; if (job.RegionGUID != null && !string.IsNullOrEmpty(job.RegionGUID.ToString())) { _store.RegionGUID = new Guid(job.RegionGUID.ToString()); _store.RegionName = _IRegionRepository.GetRegionNameByRegionGUID(_store.RegionGUID); } else { _store.RegionName = ""; } if (job.TerritoryGUID != null && !string.IsNullOrEmpty(job.TerritoryGUID.ToString())) { _store.TerritoryGUID = new Guid(job.TerritoryGUID.ToString()); _store.TerritoryName = _ITerritoryRepository.GetTerritoryNameByTerritoryGUID(_store.TerritoryGUID); } else { _store.TerritoryName = ""; } _store.StatusCode = job.StatusCode != null ? Convert.ToInt32(job.StatusCode) : 0; _store.Status = _IJobRepository.GetStatusName(_store.StatusCode); if (DateTime.TryParse(job.ActualStartTime.ToString(), out Datecontent1)) { if (Session["TimeZoneID"] != null) { _store.ActualStartTime = _IUserRepository.GetLocalDateTime(Datecontent1, Session["TimeZoneID"].ToString()); _store.ActualStartTime = Convert.ToDateTime(_store.ActualStartTime).ToString("MM/dd/yy hh:mm tt"); } else { _store.ActualStartTime = Datecontent1.ToString("MM/dd/yy hh:mm tt"); } } if (DateTime.TryParse(job.ActualEndTime.ToString(), out Datecontent2)) { if (Session["TimeZoneID"] != null) { _store.ActualEndTime = _IUserRepository.GetLocalDateTime(Datecontent2, Session["TimeZoneID"].ToString()); _store.ActualEndTime = Convert.ToDateTime(_store.ActualEndTime).ToString("MM/dd/yy hh:mm tt"); } else { _store.ActualEndTime = Datecontent2.ToString("MM/dd/yy hh:mm tt"); } } if (DateTime.TryParse(job.LastModifiedDate.ToString(), out Datecontent)) { if (Session["TimeZoneID"] != null) { _store.Date = _IUserRepository.GetLocalDateTime(Datecontent, Session["TimeZoneID"].ToString()); _store.Date = Convert.ToDateTime(_store.Date).ToString("MM/dd/yy hh:mm tt"); } else { _store.Date = Datecontent.ToString("MM/dd/yy hh:mm tt"); } } //Prabhu--While creating Job using device they are not sending location mismatch flag,so this code will not work //JobProgress ljobprogress = _IJobRepository.GetJobProgressMismatch(job.JobGUID, _store.StatusCode); //if (ljobprogress != null) // _store.LocationMismatch = ljobprogress.LocationMismatch != null ? Convert.ToBoolean(ljobprogress.LocationMismatch) : false; //else // _store.LocationMismatch = false; _store.CustomerStopGUID = job.CustomerStopGUID != null ? new Guid(job.CustomerStopGUID.ToString()) : Guid.Empty; _store.LocationMismatch = LocationMismatch(job.JobGUID, _store.CustomerStopGUID); if (_store.CustomerStopGUID != Guid.Empty) { Market _Market = _IMarketRepository.GetMarketByID(_store.CustomerStopGUID); if (_Market != null) { _store.CustomerFirstName = _Market.FirstName; _store.CustomerLastName = _Market.LastName; _store.CustomerStopName = _Market.MarketName; _store.MarketID = _Market.MarketID; 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) { _store.RMName = _userprofile.FirstName + " " + _userprofile.LastName; } else { _store.RMName = ""; } } } else { _store.RMName = ""; } //As i discussed with samant sir,he told to get FiledManager Name from GlobalUser table by using ManagerUserGUID in JobTable //if (!string.IsNullOrEmpty(_Market.FMUserID)) //{ // GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(_Market.FMUserID); // if (_globalUser != null) // { // UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, job.OrganizationGUID); // if (_userprofile != null) // { // _store.FMName = _userprofile.FirstName + " " + _userprofile.LastName; // } // else // { // _store.FMName = ""; // } // } //} //else //{ // _store.FMName = ""; //} } else { _store.CustomerStopName = ""; _store.MarketID = ""; _store.RMName = ""; //_store.FMName = ""; _store.CustomerFirstName = ""; _store.CustomerLastName = ""; } } 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) { _store.CustomerFirstName = _Market.FirstName; _store.CustomerLastName = _Market.LastName; _store.CustomerStopName = _Market.MarketName; _store.MarketID = _Market.MarketID; 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) { _store.RMName = _userprofile.FirstName + " " + _userprofile.LastName; } else { _store.RMName = ""; } } } else { _store.RMName = ""; } //As i discussed with samant sir,he told to get FiledManager Name from GlobalUser table by using ManagerUserGUID in JobTable //if (!string.IsNullOrEmpty(_Market.FMUserID)) //{ // GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByUserID(_Market.FMUserID); // if (_globalUser != null) // { // UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, job.OrganizationGUID); // if (_userprofile != null) // { // _store.FMName = _userprofile.FirstName + " " + _userprofile.LastName; // } // else // { // _store.FMName = ""; // } // } //} //else //{ // _store.FMName = ""; //} } else { _store.CustomerStopName = ""; _store.MarketID = ""; _store.RMName = ""; //_store.FMName = ""; _store.CustomerFirstName = ""; _store.CustomerLastName = ""; } } else { _store.CustomerStopName = ""; _store.MarketID = ""; _store.RMName = ""; //_store.FMName = ""; _store.CustomerFirstName = ""; _store.CustomerLastName = ""; } } else { _store.CustomerStopName = ""; _store.MarketID = ""; _store.RMName = ""; //_store.FMName = ""; _store.CustomerFirstName = ""; _store.CustomerLastName = ""; } if (job.ManagerUserGUID != null && job.ManagerUserGUID != Guid.Empty) { GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(job.ManagerUserGUID.ToString())); if (_globalUser != null) { UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(_globalUser.UserGUID, job.OrganizationGUID); if (_userprofile != null) { _store.FMName = _userprofile.FirstName + " " + _userprofile.LastName; } else { _store.FMName = ""; } } } return _store; } catch (Exception ex) { Logger.Error(ex.Message); return null; } }
private JobFormHeading GetJobFormDetails(Job _job) { if (_job != null) { Place _place = _job.CustomerGUID != null ? _IPlaceRepository.GetPlaceByID(new Guid(_job.CustomerGUID.ToString())) : null; Market _market = _job.CustomerStopGUID != null ? _IMarketRepository.GetMarketByID(new Guid(_job.CustomerStopGUID.ToString())) : null; if (_place != null && _market != null) { JobFormHeading JobFormHeading = new JobFormHeading(); JobFormHeading.JobGUID = _job.JobGUID.ToString(); JobFormHeading.JobName = _job.JobName; JobFormHeading.PlaceName = _place.PlaceName; JobFormHeading.PlaceID = _place.PlaceID; JobFormHeading.MarketName = _market.MarketName; JobFormHeading.MarketID = _market.MarketID; JobFormHeading.MarketAddress = (string.IsNullOrEmpty(_market.AddressLine1) ? "" : _market.AddressLine1 + ",") + (string.IsNullOrEmpty(_market.AddressLine2) ? "" : _market.AddressLine2 + ",") + (string.IsNullOrEmpty(_market.City) ? "" : _market.City + ",") + (string.IsNullOrEmpty(_market.State) ? "" : _market.State + ",") + (string.IsNullOrEmpty(_market.ZipCode) ? "" : _market.ZipCode); JobFormHeading.CheckInTime = (Session["TimeZoneID"] != null && !string.IsNullOrEmpty(Session["TimeZoneID"].ToString())) ? _IUserRepository.GetLocalDateTime(_job.ActualStartTime, Session["TimeZoneID"].ToString()) : DateTime.UtcNow.ToString(); JobFormHeading.CheckInTime = !string.IsNullOrEmpty(JobFormHeading.CheckInTime) ? Convert.ToDateTime(JobFormHeading.CheckInTime).ToString("MM/dd/yy hh:mm tt") : ""; JobFormHeading.CheckOutTime = (Session["TimeZoneID"] != null && !string.IsNullOrEmpty(Session["TimeZoneID"].ToString())) ? _IUserRepository.GetLocalDateTime(_job.ActualEndTime, Session["TimeZoneID"].ToString()) : DateTime.UtcNow.ToString(); JobFormHeading.CheckOutTime = !string.IsNullOrEmpty(JobFormHeading.CheckOutTime) ? Convert.ToDateTime(JobFormHeading.CheckOutTime).ToString("MM/dd/yy hh:mm tt") : ""; JobFormHeading.Status = _IJobRepository.GetStatusName(_job.StatusCode != null ? Convert.ToInt32(_job.StatusCode) : 6); JobFormHeading.PoNumber = _job.PONumber; return JobFormHeading; } else return null; } else { return null; } }
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"); } }
public ActionResult JobForm(string id = "") { Logger.Debug("Inside Job Controller- View Job"); try { if (Session["OrganizationGUID"] != null) { Job _job = new Job(); JobFormNew pJobFormView = new JobFormNew(); _job = _IJobRepository.GetJobByID(new Guid(id)); // pJobFormView.JobGUID = id; if (_job != null) { ViewBag.JobName = _job.JobName; //JobFormNew pJobFormView = (_job != null && !string.IsNullOrEmpty(_job.JobForm)) ? new JavaScriptSerializer().Deserialize<JobFormNew>(_job.JobForm) : null; //if (pJobFormView != null) //{ // if (pJobFormView.Values != null) // { // pJobFormView.FormValues = new List<JobFormValueDetails>(); // //for (int i = 0; i < pJobFormView.Values.Count; i++) // foreach (JobFormValues pFormValues in pJobFormView.Values) // { // //JobFormValues pFormValues = pJobFormView.Values[i]; // JobFormValueDetails pFormDetails = new JobFormValueDetails(); // string[] Controls = pFormValues.ControlID.Split('_'); // if (Controls.Length > 2) // { // int controlid, controltype; // pFormDetails.FormID = Controls[0]; // if (int.TryParse(Controls[1], out controlid)) // { // pFormDetails.ControlID = controlid; // } // else // { // pFormDetails.ControlID = 0; // } // if (int.TryParse(Controls[2], out controltype)) // { // pFormDetails.ControlType = (ControlType)controltype; // } // else // { // pFormDetails.ControlType = 0; // } // } // int parentid; // pFormDetails.Value = pFormValues.Value; // pFormDetails.ControlLabel = pFormValues.ControlLabel; // if (int.TryParse(pFormValues.parentID, out parentid)) // { // pFormDetails.parentID = parentid; // } // else // { // pFormDetails.parentID = 0; // } // pFormDetails.controlParentLabel = pFormValues.controlParentLabel; // pFormDetails.ValueID = pFormValues.ValueID; // pFormDetails.currentValueID = pFormValues.currentValueID; // pFormDetails.ImagePath = System.Configuration.ConfigurationManager.AppSettings.Get("ImageURL").ToString() + Session["OrganizationGUID"].ToString() + "/Jobs/" + pJobFormView.JobGUID; // pJobFormView.FormValues.Add(pFormDetails); // } // } //} if (_job != null && !string.IsNullOrEmpty(_job.JobForm)) { pJobFormView = JobFormJsonConvert(_job.JobForm, "ImageURL", _job.JobGUID.ToString()); } if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0) { JobFormHeading JobFormHeading = GetJobFormDetails(_job); if (JobFormHeading != null) { pJobFormView.JobFormHeading = JobFormHeading; ViewBag.StoreInformation = "Available"; } else { ViewBag.StoreInformation = "None"; pJobFormView.JobFormHeading = null; } pJobFormView.FormValues.OrderBy(x => x.ControlID); } return View(pJobFormView); } else { pJobFormView = null; return View(pJobFormView); } } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_A") return RedirectToAction("../JobStatus/Index"); else return RedirectToAction("Index"); } }
public ActionResult Menu() { StringBuilder sb = new StringBuilder(); Job lJob = new Job(); if (Session["UserType"] != null && Session["UserType"].ToString() == "WIM_A") { sb.Append("<ul class='page-sidebar-menu'>"); sb.Append("<li>"); sb.Append("<div class='sidebar-toggler hidden-phone'></div>"); sb.Append("</li>"); sb.Append("<li></br></li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-user'></i><span class='title'>Softtrends</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/User/Dashboard'>Dashboard</a></li>"); sb.Append("<li class=''><a href='/User/Edit/" + Session["UserGUID"].ToString() + "?Account=True'>Account</a></li>"); sb.Append("<li><a href='/Organization/Index'>Organizations</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("</ul>"); } else if (Session["UserType"] != null && (Session["UserType"].ToString() == "ENT_A")) { sb.Append("<ul class='page-sidebar-menu'>"); sb.Append("<li>"); sb.Append("<div class='sidebar-toggler hidden-phone'></div>"); sb.Append("</li>"); sb.Append("<li></br></li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-user'></i><span class='title' style='text-transform:capitalize'>" + Session["OrganizationName"].ToString() + "</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/User/Dashboard'>Dashboard</a></li>"); sb.Append("<li class=''><a href='/User/Edit/" + Session["UserGUID"].ToString() + "?Account=true'>My Account</a></li>"); sb.Append("<li class=''><a href='/MyCompany/Index'>My Company</a></li>"); //sb.Append("<li class=''><a href='/User/Index'>Users</a></li>"); //sb.Append("<li><a href='/OrganizationSubscription/Index/" + Session["OrganizationGUID"].ToString() + "'>Manage Subscription</a></li>"); //sb.Append("<li class=''><a href='/User/Dashboard'>Settings</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-group'></i><span class='title'>Client Information</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/Place/Index'>Clients</a></li>"); sb.Append("<li class=''><a href='/PO/Index'>Client POs</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); //sb.Append("<li class=''>"); //sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Visit Tracking</span><span class='arrow'></span></a>"); //sb.Append("<ul class='sub-menu' style='display: none;'>"); //sb.Append("<li class=''><a href='/JobStatus/Index'>Visit List</a></li>"); ////sb.Append("<li class=''><a href='/Job/Create'>Create Job</a></li>"); //sb.Append("</ul>"); //sb.Append("</li>"); //sb.Append("<li class=''>"); //sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Settings</span><span class='arrow'></span></a>"); //sb.Append("<ul class='sub-menu' style='display: none;'>"); //sb.Append("<li class=''><a href='/Territory/Index'><span class='badge badge-roundless badge-info'>Add/Manage</span> Territory & Region</a></li>"); //sb.Append("<li class=''><a href='/Group/Index'><span class='badge badge-roundless badge-info'>Add/Manage</span> Worker Groups</a></li>"); //sb.Append("<li class=''><a href='/ServicePoint/Index'><span class='badge badge-info'>" + _IMarketRepository.GetMarketByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), 0).Count() + "</span>Service Points</a></li>"); //sb.Append("<li class=''><a href='/JobSchema/Index'>Visit Forms</a></li>"); //sb.Append("</ul>"); //sb.Append("</li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Reports</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/StoreVisit/Index'>Store Visit Reports</a></li>"); sb.Append("<li class=''><a href='/SiteVisit/Index'>Site Visit Reports</a></li>"); sb.Append("<li class=''><a href='/UserActivities/Index'>User Activities</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("</ul>"); } else if (Session["UserType"] != null && (Session["UserType"].ToString() == "ENT_U_RM" || Session["UserType"].ToString() == "ENT_U_TM" || Session["UserType"].ToString() == "ENT_OM")) { sb.Append("<ul class='page-sidebar-menu'>"); sb.Append("<li>"); sb.Append("<div class='sidebar-toggler hidden-phone'></div>"); sb.Append("</li>"); sb.Append("<li></br></li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-user'></i><span class='title'>User</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/User/Dashboard'>Dashboard</a></li>"); sb.Append("<li class=''><a href='/User/Edit/" + Session["UserGUID"].ToString() + "?Account=true'>My Account</a></li>"); sb.Append("<li class=''><a href='/MyCompany/Index'>My Company</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-group'></i><span class='title'>Client Information</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/Place/Index'>Clients</a></li>"); sb.Append("<li class=''><a href='/PO/Index'>Client POs</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); //sb.Append("<li class=''>"); //sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Settings</span><span class='arrow'></span></a>"); //sb.Append("<ul class='sub-menu' style='display: none;'>"); //sb.Append("<li class=''><a href='/ServicePoint/Index'><span class='badge badge-info'>" + _IMarketRepository.GetMarketByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), 0).Count() + "</span>Service Points</a></li>"); //sb.Append("</ul>"); //sb.Append("</li>"); //sb.Append("<li class=''>"); //sb.Append("<a href=''><i class='icon-time'></i><span class='title'>Visit Tracking</span><span class='arrow'></span></a>"); //sb.Append("<ul class='sub-menu' style='display: none;'>"); lJob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); lJob.IsDeleted = false; //sb.Append("<li class=''><a href='/JobStatus/Index'>Visit List</a></li>"); //// sb.Append("<li class=''><a href='/Job/Create'>Create Job</a></li>"); //sb.Append("</ul>"); //sb.Append("</li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Reports</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/StoreVisit/Index'>Store Visit Reports</a></li>"); sb.Append("<li class=''><a href='/SiteVisit/Index'>Site Visit Reports</a></li>"); sb.Append("<li class=''><a href='/UserActivities/Index'>User Activities</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("</ul>"); } else if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_U") { sb.Append("<ul class='page-sidebar-menu'>"); sb.Append("<li>"); sb.Append("<div class='sidebar-toggler hidden-phone'></div>"); sb.Append("</li>"); sb.Append("<li></br></li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-user'></i><span class='title'>User</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/User/Dashboard'>Dashboard</a></li>"); sb.Append("<li class=''><a href='/User/Edit/" + Session["UserGUID"].ToString() + "?Account=true'>Account</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-group'></i><span class='title'>Client Information</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/Place/Index'>Clients</a></li>"); sb.Append("<li class=''><a href='/PO/Index'>Client POs</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); //sb.Append("<li class=''>"); //sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Settings</span><span class='arrow'></span></a>"); //sb.Append("<ul class='sub-menu' style='display: none;'>"); //sb.Append("<li class=''><a href='/ServicePoint/Index'><span class='badge badge-info'>" + _IMarketRepository.GetMarketByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString()), 0).Count() + "</span>Service Points</a></li>"); //sb.Append("</ul>"); //sb.Append("</li>"); //sb.Append("<li class=''>"); //sb.Append("<a href=''><i class='icon-time'></i><span class='title'>Visit Tracking</span><span class='arrow'></span></a>"); //sb.Append("<ul class='sub-menu' style='display: none;'>"); //sb.Append("<li class=''><a href='/JobStatus/Index'>Visit List</a></li>"); //// sb.Append("<li class=''><a href='/Job/Create'>Create Job</a></li>"); //sb.Append("</ul>"); //sb.Append("</li>"); sb.Append("<li class=''>"); sb.Append("<a href=''><i class='icon-cogs'></i><span class='title'>Reports</span><span class='arrow'></span></a>"); sb.Append("<ul class='sub-menu' style='display: none;'>"); sb.Append("<li class=''><a href='/StoreVisit/Index'>Store Visit Reports</a></li>"); sb.Append("<li class=''><a href='/SiteVisit/Index'>Site Visit Reports</a></li>"); sb.Append("<li class=''><a href='/UserActivities/Index'>User Activities</a></li>"); sb.Append("</ul>"); sb.Append("</li>"); sb.Append("</ul>"); } return Content(sb.ToString()); }
//public List<Job> GetStoreVisitJobs(Job pJob, string FieldManagerID) //{ // try // { // List<Job> ljob = new List<Job>(); // //using (var dataContext = new WorkersInMotionDB()) // //{ // // List<Market> MarketList = (from p in dataContext.Markets // // where // // (pJob.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pJob.OrganizationGUID) // // && (pJob.RegionGUID == null || pJob.RegionGUID == Guid.Empty || p.RegionGUID == pJob.RegionGUID) // // && (pJob.TerritoryGUID == null || pJob.TerritoryGUID == Guid.Empty || p.TerritoryGUID == pJob.TerritoryGUID) // // && (p.FMUserID == FieldManagerID) // // //&& ((p.CreateDate == null || (p.CreateDate != null && Convert.ToDateTime(p.CreateDate.Value.Date).Date >= pjob.ActualStartTime.Value.Date)) && (p.CreateDate == null || (p.CreateDate != null && Convert.ToDateTime(p.CreateDate.Value.Date).Date <= pjob.ActualEndTime.Value.Date))) // // && p.IsDeleted == null || p.IsDeleted == false // // select p).OrderBy(x => x.MarketName).ToList(); // // if (MarketList != null && MarketList.Count > 0) // // { // // foreach (Market market in MarketList) // // { // // List<Job> joblist = (from p in dataContext.Jobs // // where // // (pJob.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pJob.OrganizationGUID) // // && (pJob.CustomerGUID == null || pJob.CustomerGUID == Guid.Empty || p.CustomerGUID == pJob.CustomerGUID) // // && (pJob.RegionGUID == null || pJob.RegionGUID == Guid.Empty || p.RegionGUID == pJob.RegionGUID) // // && (pJob.TerritoryGUID == null || pJob.TerritoryGUID == Guid.Empty || p.TerritoryGUID == pJob.TerritoryGUID) // // && (p.CustomerStopGUID == market.MarketGUID) // // //&& ((p.PreferedStartTime == null || (p.PreferedStartTime != null && Convert.ToDateTime(p.PreferedStartTime.Value.Date).Date >= pJob.PreferedStartTime.Value.Date)) && (p.PreferedEndTime == null || (p.PreferedEndTime != null && Convert.ToDateTime(p.PreferedEndTime.Value.Date).Date <= pJob.PreferedEndTime.Value.Date))) // // && p.IsDeleted == false && p.StatusCode != 1 // // && p.JobName == pJob.JobName // // select p).OrderBy(x => x.ScheduledStartTime).ToList(); // // if (joblist != null && joblist.Count > 0) // // { // // foreach (Job jobitem in joblist) // // { // // ljob.Add(jobitem); // // } // // } // // } // // } // // if (ljob != null && ljob.Count > 0) // // { // // if (pJob.ActualStartTime != null && pJob.ActualEndTime != null) // // ljob = ljob.Where(p => (p.ActualStartTime == null || (p.ActualStartTime != null && Convert.ToDateTime(p.ActualStartTime.Value.Date).Date >= pJob.ActualStartTime.Value.Date)) && (p.ActualEndTime == null || (p.ActualEndTime != null && Convert.ToDateTime(p.ActualEndTime.Value.Date).Date <= pJob.ActualEndTime.Value.Date))).ToList(); // // return ljob; // // } // // return null; // //} // SqlParameter[] Param = new SqlParameter[46]; // Param = SetParameters(pJob); // List<Job> joblist = context.Database.SqlQuery<Job>("select * from Jobs where" // + "(OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (CustomerGUID=@pCustomerGUID OR @pCustomerGUID is NULL or @pCustomerGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (TerritoryGUID=@pTerritoryGUID OR @pTerritoryGUID is NULL or @pTerritoryGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "and IsDeleted=0 and StatusCode !=1 and JobName=@pJobName" // + "and CustomerStopGUID in(select MarketGUID from Markets where" // + "(OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (TerritoryGUID=@pTerritoryGUID OR @pTerritoryGUID is NULL or @pTerritoryGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (AssignedUserGUID=@pAssignedUserGUID OR @pAssignedUserGUID is NULL or @pAssignedUserGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (IsDeleted=0 OR @pIsDeleted is NULL)" // + "AND FMUserID='" + FieldManagerID + "')" // + " Order by ScheduledStartTime", Param).ToList(); // if (joblist != null && joblist.Count > 0) // { // if (pJob.ActualStartTime != null && pJob.ActualEndTime != null) // joblist = joblist.Where(p => (p.ActualStartTime == null || (p.ActualStartTime != null && Convert.ToDateTime(p.ActualStartTime.Value.Date).Date >= pJob.ActualStartTime.Value.Date)) && (p.ActualEndTime == null || (p.ActualEndTime != null && Convert.ToDateTime(p.ActualEndTime.Value.Date).Date <= pJob.ActualEndTime.Value.Date))).ToList(); // return joblist; // } // return null; // } // catch (Exception exception) // { // throw exception; // } //} //public List<Market> GetStoreVisitJobs(Guid OrganizationGUID, Nullable<Guid> CustomerGUID) //{ // try // { // using (var dataContext = new WorkersInMotionDB()) // { // //DateTime date = DateTime.ParseExact(DateTime.UtcNow.AddDays(-45).ToShortDateString(), "yyyy-MM-dd", CultureInfo.InvariantCulture); // DateTime date = DateTime.UtcNow.AddDays(-45); // if (CustomerGUID == null && CustomerGUID != Guid.Empty) // { // List<Market> MarketList = (from p in dataContext.Markets // where // (OrganizationGUID == Guid.Empty || p.OrganizationGUID == OrganizationGUID) // && p.IsDeleted == null || p.IsDeleted == false // select p).OrderBy(x => x.MarketName).ToList(); // if (MarketList != null && MarketList.Count > 0) // { // MarketList = MarketList.Where(p => p.LastStoreVisitedDate != null && Convert.ToDateTime(p.LastStoreVisitedDate.Value.Date).Date > date.Date).ToList(); // return MarketList; // } // return null; // } // else // { // List<Market> MarketList = (from p in dataContext.Markets // where // (OrganizationGUID == Guid.Empty || p.OrganizationGUID == OrganizationGUID) // && p.OwnerGUID == CustomerGUID // && p.IsDeleted == null || p.IsDeleted == false // select p).OrderBy(x => x.MarketName).ToList(); // if (MarketList != null && MarketList.Count > 0) // { // MarketList = MarketList.Where(p => p.LastStoreVisitedDate != null && Convert.ToDateTime(p.LastStoreVisitedDate.Value.Date).Date > date.Date).ToList(); // return MarketList; // } // return null; // } // } // } // catch (Exception exception) // { // throw exception; // } //} public List<Job> GetSiteVisitJobs(Job pJob) { try { //using (var dataContext = new WorkersInMotionDB()) //{ // List<Job> joblist = (from p in dataContext.Jobs // where // (pJob.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pJob.OrganizationGUID) // && (pJob.CustomerGUID == null || pJob.CustomerGUID == Guid.Empty || p.CustomerGUID == pJob.CustomerGUID) // && (pJob.RegionGUID == null || pJob.RegionGUID == Guid.Empty || p.RegionGUID == pJob.RegionGUID) // && (pJob.TerritoryGUID == null || pJob.TerritoryGUID == Guid.Empty || p.TerritoryGUID == pJob.TerritoryGUID) // && (pJob.AssignedUserGUID == null || pJob.AssignedUserGUID == Guid.Empty || p.AssignedUserGUID == pJob.AssignedUserGUID) // //&& ((p.PreferedStartTime == null || (p.PreferedStartTime != null && Convert.ToDateTime(p.PreferedStartTime.Value.Date).Date >= pJob.PreferedStartTime.Value.Date)) && (p.PreferedEndTime == null || (p.PreferedEndTime != null && Convert.ToDateTime(p.PreferedEndTime.Value.Date).Date <= pJob.PreferedEndTime.Value.Date))) // && p.IsDeleted == false && p.StatusCode != 1 // && p.JobName != pJob.JobName // select p).OrderBy(x => x.ScheduledStartTime).ToList(); // if (joblist != null && joblist.Count > 0) // { // if (pJob.PreferedStartTime != null && pJob.PreferedEndTime != null) // joblist = joblist.Where(p => (p.PreferedStartTime == null || (p.PreferedStartTime != null && Convert.ToDateTime(p.PreferedStartTime.Value.Date).Date >= pJob.PreferedStartTime.Value.Date)) && (p.PreferedEndTime == null || (p.PreferedEndTime != null && Convert.ToDateTime(p.PreferedEndTime.Value.Date).Date <= pJob.PreferedEndTime.Value.Date))).ToList(); // return joblist; // } // return null; //} //SqlParameter[] Param = new SqlParameter[46]; //Param = SetParameters(pJob); SqlParameter[] Param = new SqlParameter[6]; Param[0] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[0].Value = pJob.OrganizationGUID; Param[1] = new SqlParameter("@pCustomerGUID", SqlDbType.UniqueIdentifier); Param[1].Value = (object)pJob.CustomerGUID ?? DBNull.Value; Param[2] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[2].Value = (object)pJob.RegionGUID ?? DBNull.Value; Param[3] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)pJob.TerritoryGUID ?? DBNull.Value; Param[4] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[4].Value = (object)pJob.AssignedUserGUID ?? DBNull.Value; Param[5] = new SqlParameter("@pJobName", SqlDbType.NVarChar, -1); Param[5].Value = (object)pJob.JobName ?? DBNull.Value; List<Job> joblist = context.Database.SqlQuery<Job>("select * from Jobs where" + " (OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (CustomerGUID=@pCustomerGUID OR @pCustomerGUID is NULL or @pCustomerGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (TerritoryGUID=@pTerritoryGUID OR @pTerritoryGUID is NULL or @pTerritoryGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (AssignedUserGUID=@pAssignedUserGUID OR @pAssignedUserGUID is NULL or @pAssignedUserGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " and IsDeleted=0 and StatusCode !=1 and JobName != @pJobName" + " Order by ScheduledStartTime", Param).ToList(); if (joblist != null && joblist.Count > 0) { if (pJob.PreferedStartTime != null && pJob.PreferedEndTime != null) joblist = joblist.Where(p => (p.PreferedStartTime == null || (p.PreferedStartTime != null && Convert.ToDateTime(p.PreferedStartTime.Value.Date).Date >= pJob.PreferedStartTime.Value.Date)) && (p.PreferedEndTime == null || (p.PreferedEndTime != null && Convert.ToDateTime(p.PreferedEndTime.Value.Date).Date <= pJob.PreferedEndTime.Value.Date))).ToList(); return joblist; } return null; } catch (Exception exception) { throw exception; } }
public int UploadJobs(Job UploadJobRequest) { try { //using (var dataContext = new WorkersInMotionDB()) //{ // var qry = from p in dataContext.Jobs where p.JobGUID == UploadJobRequest.JobGUID select p; // var item = qry.Single(); // item.StatusCode = UploadJobRequest.StatusCode; // item.SubStatusCode = UploadJobRequest.SubStatusCode; // item.ActualStartTime = UploadJobRequest.ActualStartTime; // item.ActualEndTime = UploadJobRequest.ActualEndTime; // item.PreferedEndTime = UploadJobRequest.PreferedEndTime; // item.EstimatedDuration = UploadJobRequest.EstimatedDuration; // item.ActualDuration = UploadJobRequest.ActualDuration; // item.QuotedDuration = UploadJobRequest.QuotedDuration; // item.ScheduledEndTime = UploadJobRequest.ScheduledEndTime; // item.LastModifiedDate = DateTime.UtcNow; // item.LastModifiedBy = UploadJobRequest.LastModifiedBy; // item.JobForm = UploadJobRequest.JobForm; // return dataContext.SaveChanges(); //} Job job = GetJobByID(UploadJobRequest.JobGUID); job.StatusCode = UploadJobRequest.StatusCode; job.SubStatusCode = UploadJobRequest.SubStatusCode; job.ActualStartTime = UploadJobRequest.ActualStartTime; job.ActualEndTime = UploadJobRequest.ActualEndTime; job.PreferedEndTime = UploadJobRequest.PreferedEndTime; job.EstimatedDuration = UploadJobRequest.EstimatedDuration; job.ActualDuration = UploadJobRequest.ActualDuration; job.QuotedDuration = UploadJobRequest.QuotedDuration; job.ScheduledEndTime = UploadJobRequest.ScheduledEndTime; job.LastModifiedDate = DateTime.UtcNow; job.LastModifiedBy = UploadJobRequest.LastModifiedBy; job.JobForm = UploadJobRequest.JobForm; SqlParameter[] Param = new SqlParameter[13]; Param = SetParametersforUpdate(job); return context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode,SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime," + "ActualEndTime=@pActualEndTime,PreferedEndTime=@pPreferedEndTime,EstimatedDuration=@pEstimatedDuration,ActualDuration=@pActualDuration," + "QuotedDuration=@pQuotedDuration,ScheduledEndTime=@pScheduledEndTime,LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy," + "JobForm=@pJobForm where JobGUID=@pJobGUID", Param); } catch (Exception exception) { return 0; } }
public Job CreateJob(Job jobRequest) { Job lresponse = new Job(); try { Job job = new Job(); job.JobGUID = Guid.NewGuid(); // job.JobFormGUID = jobRequest.JobFormGUID; job.IsDeleted = false; job.OrganizationGUID = jobRequest.OrganizationGUID; job.RegionGUID = jobRequest.RegionGUID; job.TerritoryGUID = jobRequest.TerritoryGUID; job.LocationType = jobRequest.LocationType; job.CustomerGUID = jobRequest.CustomerGUID; job.StatusCode = 1; job.SubStatusCode = 0; job.CustomerStopGUID = jobRequest.CustomerStopGUID; job.JobClass = jobRequest.JobClass; job.JobForm = jobRequest.JobForm; LatLong latLong = new LatLong(); job.ServiceAddress = jobRequest.ServiceAddress; job.Latitude = jobRequest.Latitude; job.Longitude = jobRequest.Longitude; job.JobName = jobRequest.JobName; job.IsSecheduled = jobRequest.IsSecheduled; job.ManagerUserGUID = jobRequest.ManagerUserGUID; job.AssignedUserGUID = jobRequest.AssignedUserGUID; //job.EstimatedDutation = _job.JobModel.EstimatedDuration; //job.ScheduledStartTime = Convert.ToDateTime(_job.JobModel.PreferredStartTime); job.PreferedStartTime = jobRequest.PreferedStartTime; job.PreferedEndTime = jobRequest.PreferedEndTime; job.ActualStartTime = jobRequest.ActualStartTime; job.PONumber = jobRequest.PONumber; job.ScheduledStartTime = DateTime.UtcNow; job.CreateDate = DateTime.UtcNow; job.CreateBy = jobRequest.CreateBy; job.LastModifiedDate = DateTime.UtcNow; job.LastModifiedBy = jobRequest.LastModifiedBy; job.IsDeleted = false; job.IsActive = true; int result = InsertJob(job); //int result = Save(); if (result > 0) { lresponse = GetJobByID(job.JobGUID); } return lresponse; } catch (Exception ex) { return lresponse; } }
public SqlParameter[] SetParametersforUpdate(Job job) { SqlParameter[] Param = new SqlParameter[13]; Param[0] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[0].Value = job.JobGUID;// (object)globaluser.Role_Id ?? DBNull.Value; Param[1] = new SqlParameter("@pStatusCode", SqlDbType.Int); Param[1].Value = (object)job.StatusCode ?? DBNull.Value; Param[2] = new SqlParameter("@pSubStatusCode", SqlDbType.Int); Param[2].Value = (object)job.SubStatusCode ?? DBNull.Value; Param[3] = new SqlParameter("@pActualStartTime", SqlDbType.DateTime); Param[3].Value = (object)job.ActualStartTime ?? DBNull.Value; Param[4] = new SqlParameter("@pActualEndTime", SqlDbType.DateTime); Param[4].Value = (object)job.ActualEndTime ?? DBNull.Value; Param[5] = new SqlParameter("@pPreferedEndTime", SqlDbType.DateTime); Param[5].Value = (object)job.PreferedEndTime ?? DBNull.Value; Param[6] = new SqlParameter("@pScheduledEndTime", SqlDbType.DateTime); Param[6].Value = (object)job.ScheduledEndTime ?? DBNull.Value; Param[7] = new SqlParameter("@pEstimatedDuration", SqlDbType.Float); Param[7].Value = (object)job.EstimatedDuration ?? DBNull.Value; Param[8] = new SqlParameter("@pQuotedDuration", SqlDbType.Float); Param[8].Value = (object)job.QuotedDuration ?? DBNull.Value; Param[9] = new SqlParameter("@pActualDuration", SqlDbType.Float); Param[9].Value = (object)job.ActualDuration ?? DBNull.Value; Param[10] = new SqlParameter("@pJobForm", SqlDbType.Text); Param[10].Value = (object)job.JobForm ?? DBNull.Value; Param[11] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[11].Value = (object)job.LastModifiedDate ?? DBNull.Value; Param[12] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[12].Value = (object)job.LastModifiedBy ?? DBNull.Value; return Param; }
public int UpdateJobStatus(Job pJob) { int lCurrentJobStatus = 0; int lJobSaveState = 0; try { int result = 0; //using (var dataContext = new WorkersInMotionDB()) //{ // var qry = from p in dataContext.Jobs where p.JobGUID == pJob.JobGUID select p; // var lJob = qry.Single(); // lCurrentJobStatus = lJob.StatusCode != null ? (int)lJob.StatusCode : 0; // //Update Job record // lJob.StatusCode = pJob.StatusCode; // lJob.SubStatusCode = pJob.SubStatusCode; // if (pJob.StatusCode == 3) // { // lJob.ActualStartTime = pJob.ActualStartTime; // } // if (pJob.StatusCode >= 4) // { // lJob.ActualEndTime = pJob.ActualEndTime; // } // lJob.Latitude = pJob.Latitude; // lJob.Longitude = pJob.Longitude; // lJob.LastModifiedDate = DateTime.UtcNow; // lJob.LastModifiedBy = pJob.LastModifiedBy; // switch (lCurrentJobStatus) // { // case 1: // // Job Is Open Now // if (pJob.StatusCode >= 1) // { // lJob.AssignedUserGUID = null; // lJobSaveState = dataContext.SaveChanges(); // } // else // { // lJobSaveState = 0; // result = -1; // } // break; // case 2: // // Job is assigned now // if (pJob.StatusCode > 1) // { // lJob.AssignedUserGUID = pJob.AssignedUserGUID; // lJobSaveState = dataContext.SaveChanges(); // } // else // { // lJobSaveState = 0; // result = -2; // } // break; // case 3:// Job is in progress now // if (pJob.StatusCode > 2) // { // lJob.AssignedUserGUID = pJob.AssignedUserGUID; // lJobSaveState = dataContext.SaveChanges(); // } // else // { // lJobSaveState = 0; // result = -3; // } // break; // case 4: // Job is Abandon // if (pJob.StatusCode > 3) // { // lJob.AssignedUserGUID = pJob.AssignedUserGUID; // lJobSaveState = dataContext.SaveChanges(); // } // else // { // lJobSaveState = 0; // result = -4; // } // break; // case 5: // Job is Suspended // if (pJob.StatusCode > 4) // { // lJobSaveState = dataContext.SaveChanges(); // } // else // { // lJobSaveState = 0; // result = -5; // } // break; // case 6: // Job is Complete // if (pJob.StatusCode > 5) // { // lJobSaveState = dataContext.SaveChanges(); // } // else // { // lJobSaveState = 0; // result = -6; // } // break; // } //} Job lJob = GetJobByID(pJob.JobGUID); lCurrentJobStatus = lJob.StatusCode != null ? (int)lJob.StatusCode : 0; //Update Job record lJob.StatusCode = pJob.StatusCode; lJob.SubStatusCode = pJob.SubStatusCode; if (pJob.StatusCode == 3) { lJob.ActualStartTime = pJob.ActualStartTime; } if (pJob.StatusCode >= 4) { lJob.ActualEndTime = pJob.ActualEndTime; } lJob.Latitude = pJob.Latitude; lJob.Longitude = pJob.Longitude; lJob.LastModifiedDate = DateTime.UtcNow; lJob.LastModifiedBy = pJob.LastModifiedBy; SqlParameter[] Param = new SqlParameter[10]; Param[0] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[0].Value = lJob.JobGUID; Param[1] = new SqlParameter("@pStatusCode", SqlDbType.Int); Param[1].Value = lJob.StatusCode; Param[2] = new SqlParameter("@pSubStatusCode", SqlDbType.Int); Param[2].Value = lJob.SubStatusCode; Param[3] = new SqlParameter("@pActualStartTime", SqlDbType.DateTime); Param[3].Value = lJob.ActualStartTime; Param[4] = new SqlParameter("@pActualEndTime", SqlDbType.DateTime); Param[4].Value = lJob.ActualEndTime; Param[5] = new SqlParameter("@pLatitude", SqlDbType.Float); Param[5].Value = lJob.Latitude; Param[6] = new SqlParameter("@pLongitude", SqlDbType.Float); Param[6].Value = lJob.Longitude; Param[7] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[7].Value = lJob.LastModifiedDate; Param[8] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[8].Value = lJob.LastModifiedBy; switch (lCurrentJobStatus) { case 1: // Job Is Open Now if (pJob.StatusCode >= 1) { lJob.AssignedUserGUID = null; Param[9] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[9].Value = lJob.AssignedUserGUID; // lJobSaveState = dataContext.SaveChanges(); lJobSaveState = context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime,ActualEndTime=@pActualEndTime,Latitude=@pLatitude,Longitude=@pLongitude," + "LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy,AssignedUserGUID=@pAssignedUserGUID where JobGUID=@pJobGUID", Param); } else { lJobSaveState = 0; result = -1; } break; case 2: // Job is assigned now if (pJob.StatusCode > 1) { lJob.AssignedUserGUID = pJob.AssignedUserGUID; Param[9] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[9].Value = lJob.AssignedUserGUID; //lJobSaveState = dataContext.SaveChanges(); lJobSaveState = context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime,ActualEndTime=@pActualEndTime,Latitude=@pLatitude,Longitude=@pLongitude," + "LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy,AssignedUserGUID=@pAssignedUserGUID where JobGUID=@pJobGUID", Param); } else { lJobSaveState = 0; result = -2; } break; case 3:// Job is in progress now if (pJob.StatusCode > 2) { lJob.AssignedUserGUID = pJob.AssignedUserGUID; Param[9] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[9].Value = lJob.AssignedUserGUID; //lJobSaveState = dataContext.SaveChanges(); lJobSaveState = context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime,ActualEndTime=@pActualEndTime,Latitude=@pLatitude,Longitude=@pLongitude," + "LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy,AssignedUserGUID=@pAssignedUserGUID where JobGUID=@pJobGUID", Param); } else { lJobSaveState = 0; result = -3; } break; case 4: // Job is Abandon if (pJob.StatusCode > 3) { lJob.AssignedUserGUID = pJob.AssignedUserGUID; Param[9] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[9].Value = lJob.AssignedUserGUID; //lJobSaveState = dataContext.SaveChanges(); lJobSaveState = context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime,ActualEndTime=@pActualEndTime,Latitude=@pLatitude,Longitude=@pLongitude," + "LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy,AssignedUserGUID=@pAssignedUserGUID where JobGUID=@pJobGUID", Param); } else { lJobSaveState = 0; result = -4; } break; case 5: // Job is Suspended if (pJob.StatusCode > 4) { Param[9] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[9].Value = lJob.AssignedUserGUID; //lJobSaveState = dataContext.SaveChanges(); lJobSaveState = context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime,ActualEndTime=@pActualEndTime,Latitude=@pLatitude,Longitude=@pLongitude," + "LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy,AssignedUserGUID=@pAssignedUserGUID where JobGUID=@pJobGUID", Param); } else { lJobSaveState = 0; result = -5; } break; case 6: // Job is Complete if (pJob.StatusCode > 5) { Param[9] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[9].Value = lJob.AssignedUserGUID; //lJobSaveState = dataContext.SaveChanges(); lJobSaveState = context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,ActualStartTime=@pActualStartTime,ActualEndTime=@pActualEndTime,Latitude=@pLatitude,Longitude=@pLongitude," + "LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy,AssignedUserGUID=@pAssignedUserGUID where JobGUID=@pJobGUID", Param); } else { lJobSaveState = 0; result = -6; } break; } return result; } catch (Exception exception) { return 0; } }
// // GET: /JobStatus/ public ActionResult Index(string FromDate = "", string ToDate = "", string assigneduserguid = "", string jobindexguid = "", string Date = "", string selection = "", string ponumber = "", string RowCount = "", int page = 1, string search = "") { Logger.Debug("Inside AssignJob Controller- Index"); try { ViewBag.AssignedUserID = assigneduserguid; ViewBag.FromDate = FromDate; ViewBag.ToDate = ToDate; ViewBag.Date = Date; int totalPage = 0; int totalRecord = 0; int pCount = 0; if (Session["OrganizationGUID"] != null) { if (!string.IsNullOrEmpty(RowCount)) { int.TryParse(RowCount, out pCount); pageCountList(pCount); } else { pageCountList(pCount); } 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(); DateTime pFrom = new DateTime(), pTo = new DateTime(); 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(assigneduserguid)) { ViewBag.AssignedUserID = assigneduserguid; Logger.Debug("Inside AssignedUSerGUID" + assigneduserguid.ToString()); UserProfile _userprofile = _IUserProfileRepository.GetUserProfileByUserID(new Guid(assigneduserguid), pOrganizationUsersMap.OrganizationGUID); if (_userprofile != null) { sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> " + _userprofile.FirstName + " " + _userprofile.LastName + " <i class='icon-angle-down'></i></a>"); } } else { 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 User <i class='icon-angle-down'></i></a>"); } } sb.Append("<ul id='ulworkgroup' style='height:200px;overflow-y:scroll' 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", "UserActivities", new { selection = "All" }) + ">All</a></li>"); sb.Append("<li><a onclick=\"RedirectAction('');\">All</a></li>"); } List<UserProfile> pUserProfile = _IUserProfileRepository.GetUserProfilesbyOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList(); if (pUserProfile != null && pUserProfile.Count > 0) { pUserProfile = pUserProfile.OrderBy(x => x.FirstName).ToList(); foreach (UserProfile item in pUserProfile) { //sb.Append("<li><a href=" + Url.Action("Index", "UserActivities", new { assigneduserguid = item.UserGUID.ToString() }) + " data-groupguid=" + item.UserGUID + ">" + item.FirstName + " " + item.LastName + "</a></li>"); sb.Append("<li><a onclick=\"RedirectAction('" + item.UserGUID.ToString() + "');\" data-groupguid=" + item.UserGUID + ">" + item.FirstName + " " + item.LastName + "</a></li>"); Logger.Debug("Inside User foreach"); } } } sb.Append("</ul>"); sb.Append("</div>"); sb.Append("</div>"); ViewBag.UserList = sb.ToString(); Job mjob = new Job(); if (!string.IsNullOrEmpty(ponumber)) { mjob.PONumber = ponumber; TempData["PoNumber"] = ponumber; } //FOr Regional Manager if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null) { OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), new Guid(Session["OrganizationGUID"].ToString())); if (OrgUserMap != null) { mjob.RegionGUID = OrgUserMap.RegionGUID; } } if (!string.IsNullOrEmpty(FromDate) && !string.IsNullOrEmpty(ToDate) && !string.IsNullOrEmpty(assigneduserguid)) { //ViewBag.FromDate = FromDate; //ViewBag.ToDate = ToDate; Logger.Debug("Inside 1"); if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_U") { mjob.AssignedUserGUID = new Guid(assigneduserguid); if (ParseExact(FromDate, "dd-MM-yyyy", out pFrom)) { mjob.ActualStartTime = pFrom; } else { Logger.Debug("From else"); mjob.ActualStartTime = DateTime.Now.AddDays(-29); } if (ParseExact(ToDate, "dd-MM-yyyy", out pTo)) { mjob.ActualEndTime = pTo; } else { Logger.Debug("To else"); mjob.ActualEndTime = DateTime.Now; } mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); jobGroup = _IJobRepository.GetJobs(mjob); } else { Logger.Debug("Inside 1 else"); mjob.AssignedUserGUID = new Guid(assigneduserguid); if (ParseExact(FromDate, "dd-MM-yyyy", out pFrom)) { mjob.ActualStartTime = pFrom; } else { Logger.Debug("From else 1"); mjob.ActualStartTime = DateTime.Now.AddDays(-29); } if (ParseExact(ToDate, "dd-MM-yyyy", out pTo)) { mjob.ActualEndTime = pTo; } else { Logger.Debug("To Else 1"); mjob.ActualEndTime = DateTime.Now; } // mjob.PreferedEndTime = _IUserRepository.GetLocalDateTime(mjob.PreferedEndTime, Session["TimeZoneID"].ToString()); mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); jobGroup = _IJobRepository.GetJobs(mjob); } } else if (!string.IsNullOrEmpty(FromDate) && !string.IsNullOrEmpty(ToDate)) { Logger.Debug("Inside 2"); if (Session["UserType"] != null && Session["UserType"].ToString() == "ENT_U") { if (ParseExact(FromDate, "dd-MM-yyyy", out pFrom)) { mjob.ActualStartTime = pFrom; } else { Logger.Debug("From else"); mjob.ActualStartTime = DateTime.Now.AddDays(-29); } if (ParseExact(ToDate, "dd-MM-yyyy", out pTo)) { mjob.ActualEndTime = pTo; } else { Logger.Debug("To else"); mjob.ActualEndTime = DateTime.Now; } mjob.AssignedUserGUID = new Guid(Session["UserGUID"].ToString()); mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); jobGroup = _IJobRepository.GetJobs(mjob); } else { Logger.Debug("Inside 3"); if (ParseExact(FromDate, "dd-MM-yyyy", out pFrom)) { mjob.ActualStartTime = pFrom; } else { Logger.Debug("From Else"); mjob.ActualStartTime = DateTime.Now.AddDays(-29); } if (ParseExact(ToDate, "dd-MM-yyyy", out pTo)) { mjob.ActualEndTime = pTo; } else { Logger.Debug("To Else"); mjob.ActualEndTime = DateTime.Now; } mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); jobGroup = _IJobRepository.GetJobs(mjob); } } else if (!string.IsNullOrEmpty(assigneduserguid)) { mjob.ActualStartTime = DateTime.Now.AddDays(-29); mjob.ActualEndTime = DateTime.Now; mjob.AssignedUserGUID = new Guid(assigneduserguid); 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.AssignedUserGUID = new Guid(Session["UserGUID"].ToString()); mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); jobGroup = _IJobRepository.GetJobs(mjob); } else { mjob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); jobGroup = _IJobRepository.GetJobs(mjob); } } if (jobGroup != null && jobGroup.Count > 0) { ViewBag.Search = search; if (!string.IsNullOrEmpty(search)) { search = search.ToLower(); jobGroup = jobGroup.Where(x => (x.CustomerGUID != null ? GetCompanyName(x.CustomerGUID).ToLower() : GetCompanyNameByPO(x.PONumber).ToLower()).Contains(search) || (!String.IsNullOrEmpty(x.JobName) && x.JobName.ToLower().Contains(search)) || (!String.IsNullOrEmpty(x.PONumber) && x.PONumber.ToLower().Contains(search)) || (!string.IsNullOrEmpty(x.CustomerGUID.ToString()) ? getStoreID(x.CustomerStopGUID.ToString()) : "").Contains(search) || (_IJobRepository.GetStatusName(Convert.ToInt32(x.StatusCode)).ToLower().Contains(search)) ).ToList(); } totalRecord = jobGroup.ToList().Count; totalPage = (totalRecord / (int)ViewBag.pageCountValue) + ((totalRecord % (int)ViewBag.pageCountValue) > 0 ? 1 : 0); ViewBag.TotalRows = totalRecord; jobGroup = jobGroup.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageCountValue)).Take((int)ViewBag.pageCountValue).ToList(); 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 = ""; } 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 = ""; } } 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, pOrganizationUsersMap.OrganizationGUID); if (_userprofile != null) { js.RegionalManager = _userprofile.FirstName + " " + _userprofile.LastName; } else { js.RegionalManager = ""; } } } else { js.RegionalManager = ""; } } else { js.RegionalManager = ""; //js.FieldManager = ""; } } else { js.RegionalManager = ""; //js.FieldManager = ""; } } else { js.RegionalManager = ""; // js.FieldManager = ""; } if (job.ManagerUserGUID != null && job.ManagerUserGUID != Guid.Empty) { GlobalUser _globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(job.ManagerUserGUID.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 = ""; } jobStatus.JobStatusModel.Add(js); } } else { ViewBag.TotalRows = 0; } if (!string.IsNullOrEmpty(assigneduserguid) && !string.IsNullOrEmpty(jobindexguid)) { GlobalUser _GlobalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(assigneduserguid)); jobStatus.GlobalUsers = new List<GlobalUserModel>(); if (_GlobalUser != null) { jobStatus.GlobalUsers.Add(new GlobalUserModel { UserGUID = _GlobalUser.UserGUID, UserName = _GlobalUser.UserName }); } if (!string.IsNullOrEmpty(jobindexguid)) { jobStatus.JobModel = new JobModel(); jobStatus.JobModel.JobName = _IJobRepository.GetJobByID(new Guid(jobindexguid)).JobName; jobStatus.JobModel.JobIndexGUID = new Guid(jobindexguid); } } } if (jobStatus.JobStatusModel != null && jobStatus.JobStatusModel.Count > 0) { if (Session["JobStatusModel"] != null) { Session["JobStatusModel"] = null; Session["JobStatusModel"] = jobStatus.JobStatusModel.ToList(); } else { Session["JobStatusModel"] = jobStatus.JobStatusModel.ToList(); } } else { Session["JobStatusModel"] = null; } if (!string.IsNullOrEmpty(RowCount)) ViewBag.pageCountValue = int.Parse(RowCount); else ViewBag.pageCountValue = 5; return View(jobStatus); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return RedirectToAction("Login", "User"); } }
// // 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"); } }
//public IEnumerable<Job> GetJobByUserGUIDForServer(Guid UserGUID) //{ // using (var dataContext = new WorkersInMotionJobDB()) // { // return (from p in dataContext.Jobs // where p.AssignedUserGUID == UserGUID // select p).ToList().OrderBy(x => x.ScheduledStartTime); // } //} public SqlParameter[] SetParametersForStoreCreate(Job job) { SqlParameter[] Param = new SqlParameter[28]; Param[0] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[0].Value = job.JobGUID;// (object)globaluser.Role_Id ?? DBNull.Value; Param[1] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[1].Value = job.OrganizationGUID; Param[2] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[2].Value = (object)job.RegionGUID ?? DBNull.Value; Param[3] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)job.TerritoryGUID ?? DBNull.Value; Param[4] = new SqlParameter("@pLocationType", SqlDbType.SmallInt); Param[4].Value = (object)job.LocationType ?? DBNull.Value; Param[5] = new SqlParameter("@pCustomerGUID", SqlDbType.UniqueIdentifier); Param[5].Value = (object)job.CustomerGUID ?? DBNull.Value; Param[6] = new SqlParameter("@pCustomerStopGUID", SqlDbType.UniqueIdentifier); Param[6].Value = (object)job.CustomerStopGUID ?? DBNull.Value; Param[7] = new SqlParameter("@pServiceAddress", SqlDbType.NVarChar, -1); Param[7].Value = (object)job.ServiceAddress ?? DBNull.Value; Param[8] = new SqlParameter("@pLatitude", SqlDbType.Float); Param[8].Value = (object)job.Latitude ?? DBNull.Value; Param[9] = new SqlParameter("@pLongitude", SqlDbType.Float); Param[9].Value = (object)job.Longitude ?? DBNull.Value; Param[10] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[10].Value = (object)job.AssignedUserGUID ?? DBNull.Value; Param[11] = new SqlParameter("@pManagerUserGUID", SqlDbType.UniqueIdentifier); Param[11].Value = (object)job.ManagerUserGUID ?? DBNull.Value; Param[12] = new SqlParameter("@pIsActive", SqlDbType.Bit); Param[12].Value = (object)job.IsActive ?? DBNull.Value; Param[13] = new SqlParameter("@pIsDeleted", SqlDbType.Bit); Param[13].Value = (object)job.IsDeleted ?? DBNull.Value; Param[14] = new SqlParameter("@pIsUrgent", SqlDbType.Bit); Param[14].Value = (object)job.IsUrgent ?? DBNull.Value; Param[15] = new SqlParameter("@pStatusCode", SqlDbType.Int); Param[15].Value = (object)job.StatusCode ?? DBNull.Value; Param[16] = new SqlParameter("@pSubStatusCode", SqlDbType.Int); Param[16].Value = (object)job.SubStatusCode ?? DBNull.Value; Param[17] = new SqlParameter("@pIsSecheduled", SqlDbType.Bit); Param[17].Value = (object)job.IsSecheduled ?? DBNull.Value; Param[18] = new SqlParameter("@pJobName", SqlDbType.NVarChar, -1); Param[18].Value = (object)job.JobName ?? DBNull.Value; Param[19] = new SqlParameter("@pPreferedStartTime", SqlDbType.DateTime); Param[19].Value = (object)job.PreferedStartTime ?? DBNull.Value; Param[20] = new SqlParameter("@pPreferedEndTime", SqlDbType.DateTime); Param[20].Value = (object)job.PreferedEndTime ?? DBNull.Value; Param[21] = new SqlParameter("@pScheduledStartTime", SqlDbType.DateTime); Param[21].Value = job.ScheduledStartTime.ToString("MM-dd-yyyy") == "01-01-0001" ? DateTime.UtcNow.AddYears(-10) : job.ScheduledStartTime; Param[22] = new SqlParameter("@pActualStartTime", SqlDbType.DateTime); Param[22].Value = (object)job.ActualStartTime ?? DBNull.Value; Param[23] = new SqlParameter("@pJobClass", SqlDbType.SmallInt); Param[23].Value = (object)job.JobClass ?? DBNull.Value; Param[24] = new SqlParameter("@pCreateDate", SqlDbType.DateTime); Param[24].Value = (object)job.CreateDate ?? DBNull.Value; Param[25] = new SqlParameter("@pCreateBy", SqlDbType.UniqueIdentifier); Param[25].Value = (object)job.CreateBy ?? DBNull.Value; Param[26] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[26].Value = (object)job.LastModifiedDate ?? DBNull.Value; Param[27] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[27].Value = (object)job.LastModifiedBy ?? DBNull.Value; return Param; }
public SqlParameter[] SetParameters(Job job) { SqlParameter[] Param = new SqlParameter[46]; Param[0] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[0].Value = job.JobGUID;// (object)globaluser.Role_Id ?? DBNull.Value; Param[1] = new SqlParameter("@pJobReferenceNo", SqlDbType.NVarChar, -1); Param[1].Value = (object)job.JobReferenceNo ?? DBNull.Value; Param[2] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[2].Value = job.OrganizationGUID; Param[3] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)job.RegionGUID ?? DBNull.Value; Param[4] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[4].Value = (object)job.TerritoryGUID ?? DBNull.Value; Param[5] = new SqlParameter("@pLocationType", SqlDbType.SmallInt); Param[5].Value = (object)job.LocationType ?? DBNull.Value; Param[6] = new SqlParameter("@pCustomerGUID", SqlDbType.UniqueIdentifier); Param[6].Value = (object)job.CustomerGUID ?? DBNull.Value; Param[7] = new SqlParameter("@pCustomerStopGUID", SqlDbType.UniqueIdentifier); Param[7].Value = (object)job.CustomerStopGUID ?? DBNull.Value; Param[8] = new SqlParameter("@pServicePointGUID", SqlDbType.UniqueIdentifier); Param[8].Value = (object)job.ServicePointGUID ?? DBNull.Value; Param[9] = new SqlParameter("@pServiceAddress", SqlDbType.NVarChar, -1); Param[9].Value = (object)job.ServiceAddress ?? DBNull.Value; Param[10] = new SqlParameter("@pLatitude", SqlDbType.Float); Param[10].Value = (object)job.Latitude ?? DBNull.Value; Param[11] = new SqlParameter("@pLongitude", SqlDbType.Float); Param[11].Value = (object)job.Longitude ?? DBNull.Value; Param[12] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[12].Value = (object)job.AssignedUserGUID ?? DBNull.Value; Param[13] = new SqlParameter("@pManagerUserGUID", SqlDbType.UniqueIdentifier); Param[13].Value = (object)job.ManagerUserGUID ?? DBNull.Value; Param[14] = new SqlParameter("@pIsActive", SqlDbType.Bit); Param[14].Value = (object)job.IsActive ?? DBNull.Value; Param[15] = new SqlParameter("@pIsDeleted", SqlDbType.Bit); Param[15].Value = (object)job.IsDeleted ?? DBNull.Value; Param[16] = new SqlParameter("@pIsUrgent", SqlDbType.Bit); Param[16].Value = (object)job.IsUrgent ?? DBNull.Value; Param[17] = new SqlParameter("@pStatusCode", SqlDbType.Int); Param[17].Value = (object)job.StatusCode ?? DBNull.Value; Param[18] = new SqlParameter("@pSubStatusCode", SqlDbType.Int); Param[18].Value = (object)job.SubStatusCode ?? DBNull.Value; Param[19] = new SqlParameter("@pIsSecheduled", SqlDbType.Bit); Param[19].Value = (object)job.IsSecheduled ?? DBNull.Value; Param[20] = new SqlParameter("@pJobName", SqlDbType.NVarChar, -1); Param[20].Value = (object)job.JobName ?? DBNull.Value; Param[21] = new SqlParameter("@pPreferedStartTime", SqlDbType.DateTime); Param[21].Value = (object)job.PreferedStartTime ?? DBNull.Value; Param[22] = new SqlParameter("@pPreferedEndTime", SqlDbType.DateTime); Param[22].Value = (object)job.PreferedEndTime ?? DBNull.Value; Param[23] = new SqlParameter("@pScheduledStartTime", SqlDbType.DateTime); Param[23].Value = job.ScheduledStartTime.ToString("MM-dd-yyyy") == "01-01-0001" ? DateTime.UtcNow.AddYears(-10) : job.ScheduledStartTime; Param[24] = new SqlParameter("@pScheduledEndTime", SqlDbType.DateTime); Param[24].Value = (object)job.ScheduledEndTime ?? DBNull.Value; Param[25] = new SqlParameter("@pActualStartTime", SqlDbType.DateTime); Param[25].Value = (object)job.ActualStartTime ?? DBNull.Value; Param[26] = new SqlParameter("@pActualEndTime", SqlDbType.DateTime); Param[26].Value = (object)job.ActualEndTime ?? DBNull.Value; Param[27] = new SqlParameter("@pEstimatedDuration", SqlDbType.Float); Param[27].Value = (object)job.EstimatedDuration ?? DBNull.Value; Param[28] = new SqlParameter("@pQuotedDuration", SqlDbType.Float); Param[28].Value = (object)job.QuotedDuration ?? DBNull.Value; Param[29] = new SqlParameter("@pActualDuration", SqlDbType.Float); Param[29].Value = (object)job.ActualDuration ?? DBNull.Value; Param[30] = new SqlParameter("@pCostType", SqlDbType.SmallInt); Param[30].Value = (object)job.CostType ?? DBNull.Value; Param[31] = new SqlParameter("@pQuotedCost", SqlDbType.Float); Param[31].Value = (object)job.QuotedCost ?? DBNull.Value; Param[32] = new SqlParameter("@pActualCost", SqlDbType.Float); Param[32].Value = (object)job.ActualCost ?? DBNull.Value; Param[33] = new SqlParameter("@pJobForm", SqlDbType.Text); Param[33].Value = (object)job.JobForm ?? DBNull.Value; Param[34] = new SqlParameter("@pJobClass", SqlDbType.SmallInt); Param[34].Value = (object)job.JobClass ?? DBNull.Value; Param[35] = new SqlParameter("@pSignOffRequired", SqlDbType.SmallInt); Param[35].Value = (object)job.SignOffRequired ?? DBNull.Value; Param[36] = new SqlParameter("@pSignoffName", SqlDbType.NVarChar, -1); Param[36].Value = (object)job.SignoffName ?? DBNull.Value; Param[37] = new SqlParameter("@pPictureRequired", SqlDbType.SmallInt); Param[37].Value = (object)job.PictureRequired ?? DBNull.Value; Param[38] = new SqlParameter("@pPictureDescription", SqlDbType.NVarChar, -1); Param[38].Value = (object)job.PictureDescription ?? DBNull.Value; Param[39] = new SqlParameter("@pLocationSpecific", SqlDbType.Bit); Param[39].Value = (object)job.LocationSpecific ?? DBNull.Value; Param[40] = new SqlParameter("@pPONumber", SqlDbType.NVarChar, 50); Param[40].Value = (object)job.PONumber ?? DBNull.Value; Param[41] = new SqlParameter("@pTermsURL", SqlDbType.NVarChar, -1); Param[41].Value = (object)job.TermsURL ?? DBNull.Value; Param[42] = new SqlParameter("@pCreateDate", SqlDbType.DateTime); Param[42].Value = (object)job.CreateDate ?? DBNull.Value; Param[43] = new SqlParameter("@pCreateBy", SqlDbType.UniqueIdentifier); Param[43].Value = (object)job.CreateBy ?? DBNull.Value; Param[44] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[44].Value = (object)job.LastModifiedDate ?? DBNull.Value; Param[45] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[45].Value = (object)job.LastModifiedBy ?? DBNull.Value; return Param; }
public List<Job> GetJobStatus(Job pJob) { try { //using (var dataContext = new WorkersInMotionDB()) //{ // return (from p in dataContext.Jobs // where // (pJob.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pJob.OrganizationGUID) // && (pJob.AssignedUserGUID == null || pJob.AssignedUserGUID == Guid.Empty || p.AssignedUserGUID == pJob.AssignedUserGUID) // && (pJob.RegionGUID == null || pJob.RegionGUID == Guid.Empty || p.RegionGUID == pJob.RegionGUID) // && (pJob.TerritoryGUID == null || pJob.TerritoryGUID == Guid.Empty || p.TerritoryGUID == pJob.TerritoryGUID) // && (pJob.JobGUID == Guid.Empty || p.JobGUID == pJob.TerritoryGUID) // && p.StatusCode >= 2 && p.IsDeleted == false // select p).OrderBy(x => x.ScheduledStartTime).ToList(); //} //SqlParameter[] Param = new SqlParameter[46]; //Param = SetParameters(pJob); SqlParameter[] Param = new SqlParameter[5]; Param[0] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[0].Value = pJob.OrganizationGUID; Param[1] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[1].Value = pJob.JobGUID; Param[2] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[2].Value = (object)pJob.RegionGUID ?? DBNull.Value; Param[3] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)pJob.TerritoryGUID ?? DBNull.Value; Param[4] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[4].Value = (object)pJob.AssignedUserGUID ?? DBNull.Value; return context.Database.SqlQuery<Job>("select * from Jobs where" + " (OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (AssignedUserGUID=@pAssignedUserGUID OR @pAssignedUserGUID is NULL or @pAssignedUserGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (TerritoryGUID=@pTerritoryGUID OR @pTerritoryGUID is NULL or @pTerritoryGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (JobGUID=@pJobGUID or @pJobGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " and IsDeleted=0 and StatusCode >=2" + " Order by ScheduledStartTime", Param).ToList(); } catch (Exception exception) { throw exception; } }
public int AssignJob(Job _Job) { try { //using (var dataContext = new WorkersInMotionDB()) //{ // var qry = from p in dataContext.Jobs where p.JobGUID == _Job.JobGUID select p; // var item = qry.Single(); // if (item.StatusCode < 2 && item.AssignedUserGUID == null) // { // item.AssignedUserGUID = _Job.AssignedUserGUID; // item.LastModifiedDate = DateTime.UtcNow; // item.LastModifiedBy = _Job.LastModifiedBy; // item.StatusCode = 2; // return dataContext.SaveChanges(); // } // else // { // if (item.AssignedUserGUID != _Job.AssignedUserGUID) // { // //Job is assigned to another user. // return -1; // } // else // { // // Job is already in progress or completed // return -2; // } // } //} Job job = GetJobByID(_Job.JobGUID); if (job.StatusCode < 2 && job.AssignedUserGUID == null) { job.AssignedUserGUID = _Job.AssignedUserGUID; job.LastModifiedDate = DateTime.UtcNow; job.LastModifiedBy = _Job.LastModifiedBy; job.StatusCode = 2; SqlParameter[] Param = new SqlParameter[5]; Param[0] = new SqlParameter("@pAssignedUserGUID", SqlDbType.UniqueIdentifier); Param[0].Value = job.AssignedUserGUID; Param[1] = new SqlParameter("@pLastModifiedDate", SqlDbType.DateTime); Param[1].Value = job.LastModifiedDate; Param[2] = new SqlParameter("@pLastModifiedBy", SqlDbType.UniqueIdentifier); Param[2].Value = job.LastModifiedBy; Param[3] = new SqlParameter("@pStatusCode", SqlDbType.Int); Param[3].Value = job.StatusCode; Param[4] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[4].Value = job.JobGUID; return context.Database.ExecuteSqlCommand("update Jobs set AssignedUserGUID=@pAssignedUserGUID,LastModifiedDate=@pLastModifiedDate," + "LastModifiedBy=@pLastModifiedBy,StatusCode=@pStatusCode where JobGUID=@pJobGUID", Param); } else { if (job.AssignedUserGUID != _Job.AssignedUserGUID) { //Job is assigned to another user. return -1; } else { // Job is already in progress or completed return -2; } } } catch (Exception exception) { return 0; } }
public ActionResult PendingJobList() { StringBuilder sb = new StringBuilder(); Job lJob = new Job(); Logger.Debug("Inside User Controller- Pending Job List"); try { if (Session["UserType"] != null && Session["UserType"].ToString() != "WIM_A" && Session["UserType"].ToString() != "ENT_A") { lJob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); lJob.IsDeleted = false; int jscount = _IJobRepository.GetOpenJobs(lJob).ToList().Count; sb.Append("<li class='dropdown' id='header_notification_bar'>"); sb.Append("<a href='#' class='dropdown-toggle' data-toggle='dropdown' data-hover='dropdown' data-close-others='true'>"); sb.Append("<i class='icon-warning-sign'></i>"); sb.Append("<span class='badge'>" + jscount + "</span>"); sb.Append("</a>"); sb.Append("<ul class='dropdown-menu extended notification'>"); sb.Append("<li>"); sb.Append("<p id='pjobstatus'>You have " + jscount + " pending in queue"); sb.Append("</p>"); sb.Append("</li>"); sb.Append("<li>"); // sb.Append("<div class='slimScrollDiv' style='position: relative; overflow: hidden; width: auto; height: 100px;'>"); sb.Append("<ul class='dropdown-menu-list scroller' style='height: 100px; overflow: hidden; width: auto;'>"); List<Job> ListJob = _IJobRepository.GetOpenJobs(lJob).ToList(); if (ListJob != null && ListJob.Count > 0) { foreach (Job job in ListJob) { sb.Append("<li><a href='#'><span class='label label-sm label-icon label-info'><i class='icon-bell'></i></span>" + job.JobName + " | <span class='time'>" + _IJobRepository.GetCustomerName(new Guid(job.CustomerGUID.ToString())) + "</span></a></li>"); } } sb.Append("</ul>"); sb.Append("</li>"); sb.Append("<li class='external'>"); if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_U") { sb.Append("<a href='/Job/Index'>See Pending Job Report<i class='m-icon-swapright'></i></a>"); } else { sb.Append("<a href='#'>See Pending Job Report<i class='m-icon-swapright'></i></a>"); } sb.Append("</li>"); sb.Append("</ul>"); sb.Append("</li>"); } } catch (Exception ex) { sb.Clear(); sb.Length = 0; sb.Append(""); Logger.Error(ex.Message); } return Content(sb.ToString()); }
public int InsertJob(Job job) { try { //context.Jobs.Add(job); SqlParameter[] Param = new SqlParameter[46]; Param = SetParameters(job); return context.Database.ExecuteSqlCommand("insert into Jobs(JobGUID,JobReferenceNo,OrganizationGUID,RegionGUID,TerritoryGUID,LocationType,CustomerGUID," + "CustomerStopGUID,ServicePointGUID,ServiceAddress,Latitude,Longitude,AssignedUserGUID,ManagerUserGUID,IsActive,IsDeleted,IsUrgent,StatusCode," + "SubStatusCode,IsSecheduled,JobName,PreferedStartTime,PreferedEndTime,ScheduledStartTime,ScheduledEndTime,ActualStartTime,ActualEndTime," + "EstimatedDuration,QuotedDuration,ActualDuration,CostType,QuotedCost,ActualCost,JobForm,JobClass,SignOffRequired,SignoffName,PictureRequired," + "PictureDescription,LocationSpecific,PONumber,TermsURL,CreateDate,CreateBy,LastModifiedDate,LastModifiedBy)" + "values(@pJobGUID,@pJobReferenceNo,@pOrganizationGUID,@pRegionGUID,@pTerritoryGUID,@pLocationType,@pCustomerGUID," + "@pCustomerStopGUID,@pServicePointGUID,@pServiceAddress,@pLatitude,@pLongitude,@pAssignedUserGUID,@pManagerUserGUID,@pIsActive,@pIsDeleted,@pIsUrgent,@pStatusCode," + "@pSubStatusCode,@pIsSecheduled,@pJobName,@pPreferedStartTime,@pPreferedEndTime,@pScheduledStartTime,@pScheduledEndTime,@pActualStartTime,@pActualEndTime," + "@pEstimatedDuration,@pQuotedDuration,@pActualDuration,@pCostType,@pQuotedCost,@pActualCost,@pJobForm,@pJobClass,@pSignOffRequired,@pSignoffName,@pPictureRequired," + "@pPictureDescription,@pLocationSpecific,@pPONumber,@pTermsURL,@pCreateDate,@pCreateBy,@pLastModifiedDate,@pLastModifiedBy)", Param); } catch (Exception ex) { return 0; } }
public ActionResult DashBoard(string pDay = "", string selection = "", string pDayUser = "", string selectionUser = "", string RowCount = "", int page = 1, string search = "") { Logger.Debug("Inside User Controller- Index"); try { int totalPage = 0; int totalRecord = 0; int pCount = 0; if (Session["OrganizationGUID"] != null) { if (!string.IsNullOrEmpty(RowCount)) { int.TryParse(RowCount, out pCount); pageCountList(pCount); } else { pageCountList(pCount); } Job lJob = new Job(); lJob.AssignedUserGUID = new Guid(Session["UserGUID"].ToString()); lJob.IsDeleted = false; lJob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); ViewBag.Flag = "false"; #region Dropdown if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_A") { StringBuilder sb = new StringBuilder(); sb.Append("<div class='actions'>"); sb.Append("<div class='btn-group'>"); if (!string.IsNullOrEmpty(pDay)) { pDay = _IUserRepository.DecodeFrom64(pDay); sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pDay + " <i class='icon-angle-down'></i></a>"); } else { //if (!string.IsNullOrEmpty(selection) && selection == "Current Period") //{ sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> Current Period <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 <i class='icon-angle-down'></i></a>"); //} } sb.Append("<ul id='ulworkgroup' class='dropdown-menu pull-right'>"); //if (!string.IsNullOrEmpty(selection) || selection != "Current Period") //{ // sb.Append("<li><a href=" + Url.Action("DashBoard", "User", new { selection = "Current Period" }) + ">Current Period</a></li>"); //} if (!string.IsNullOrEmpty(pDay)) { if (pDay != "Current Period") { sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Current Period") }) + " data-groupguid='>Current Period'>Current Period</a></li>"); } if (pDay != "Period 2") { sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 2") }) + " data-groupguid='Period 2'>Period 2</a></li>"); } if (pDay != "Period 3") { sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 3") }) + " data-groupguid='Period 3'>Period 3</a></li>"); } if (pDay != "Period 4") { sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 4") }) + " data-groupguid='Period 4'>Period 4</a></li>"); } if (pDay != "Period 5") { sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 5") }) + " data-groupguid='Period 5'>Period 5</a></li>"); } if (pDay != "Period 6") { sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 6") }) + " data-groupguid='Period 6'>Period 6</a></li>"); } } else { //sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Current Period") }) + " data-groupguid='Current Period'>Current Period</a></li>"); sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 2") }) + " data-groupguid='Period 2'>Period 2</a></li>"); sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 3") }) + " data-groupguid='Period 3'>Period 3</a></li>"); sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 4") }) + " data-groupguid='Period 4'>Period 4</a></li>"); sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 5") }) + " data-groupguid='Period 5'>Period 5</a></li>"); sb.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDay = _IUserRepository.EncodeTo64("Period 6") }) + " data-groupguid='Period 6'>Period 6</a></li>"); } sb.Append("</ul>"); sb.Append("</div>"); sb.Append("</div>"); ViewBag.FilterList = sb.ToString(); } else { ViewBag.FilterList = ""; } #endregion #region Dropdown User Activity StringBuilder sbUser = new StringBuilder(); sbUser.Append("<div class='actions'>"); sbUser.Append("<div class='btn-group'>"); if (!string.IsNullOrEmpty(pDayUser)) { pDayUser = _IUserRepository.DecodeFrom64(pDayUser); sbUser.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pDayUser + " <i class='icon-angle-down'></i></a>"); } else { if (!string.IsNullOrEmpty(selectionUser) && selectionUser == "All") { sbUser.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 { sbUser.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i> Select <i class='icon-angle-down'></i></a>"); } } sbUser.Append("<ul id='ulworkgroup' class='dropdown-menu pull-right'>"); if (string.IsNullOrEmpty(selectionUser) || selectionUser != "All") { sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { selectionUser = "******" }) + ">All</a></li>"); } if (!string.IsNullOrEmpty(pDayUser)) { if (pDayUser != "Today") { sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("Today") }) + " data-groupguid='Today'>Today</a></li>"); } if (pDayUser != "7 Days") { sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("7 Days") }) + " data-groupguid='7 Days'>7 Days</a></li>"); } if (pDayUser != "30 Days") { sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("30 Days") }) + " data-groupguid=30 Days'>30 Days</a></li>"); } } else { sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("Today") }) + " data-groupguid='Today'>Today</a></li>"); sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("7 Days") }) + " data-groupguid='7 Days'>7 Days</a></li>"); sbUser.Append("<li><a href=" + Url.Action("Dashboard", "User", new { pDayUser = _IUserRepository.EncodeTo64("30 Days") }) + " data-groupguid=30 Days'>30 Days</a></li>"); } sbUser.Append("</ul>"); sbUser.Append("</div>"); sbUser.Append("</div>"); ViewBag.UserActivityDropdown = sbUser.ToString(); #endregion #region Pie Chart Market _Market = new Market(); _Market.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); if (!string.IsNullOrEmpty(pDay)) { switch (pDay) { case "Current Period": _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-45); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; case "Period 2": _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-52); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-52).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-52).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; case "Period 3": _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-59); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-59).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-59).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; case "Period 4": _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-66); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-66).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-66).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; case "Period 5": _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-73); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-73).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-73).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; case "Period 6": _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-80); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-80).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-80).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; default: _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-45); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); break; } } else { _Market.LastStoreVisitedDate = DateTime.UtcNow.Date.AddDays(-45); ViewBag.LastModifiedDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy"); ViewBag.FromDate = DateTime.UtcNow.Date.AddDays(-45).ToString("dd-MM-yyyy"); ViewBag.ToDate = DateTime.UtcNow.Date.ToString("dd-MM-yyyy"); } int jobCount = 0; // List<Job> pjobVistList = pjobList.Where(x => x.LastModifiedDate >= DateTime.UtcNow.AddDays(-45)).ToList(); string FieldManagerName = string.Empty; List<Market> pAllStoreList = new List<Market>(); List<Market> pStoreNonVistList = new List<Market>(); //FOr Regional Manager if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null) { OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), new Guid(Session["OrganizationGUID"].ToString())); if (OrgUserMap != null) { _Market.RegionGUID = OrgUserMap.RegionGUID; } } //check the current user is Field Manager or not if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null) { GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString())); if (globalUser != null) { //FieldManagerName = globalUser.USERID; _Market.FMUserID = globalUser.USERID; } } pStoreNonVistList = _IMarketRepository.GetStoreNonVisit(_Market); pAllStoreList = _IMarketRepository.GetAllStores(_Market); JobStatusPercentageList pJobStatusPercentageList = new JobStatusPercentageList(); pJobStatusPercentageList.data = new List<JobStatusPercentage>(); if (pAllStoreList != null && pAllStoreList.Count > 0 && pStoreNonVistList != null && pStoreNonVistList.Count > 0) { jobCount = pAllStoreList.Count; JobStatusPercentage rJobStatusPercentage = new JobStatusPercentage(); rJobStatusPercentage.label = "Visit"; rJobStatusPercentage.data = (int)Math.Round((decimal)((pAllStoreList.Count - pStoreNonVistList.Count) * 100) / jobCount); pJobStatusPercentageList.data.Add(rJobStatusPercentage); JobStatusPercentage pJobStatusPercentage = new JobStatusPercentage(); pJobStatusPercentage.label = "Non Visit"; pJobStatusPercentage.data = (int)Math.Round((decimal)(pStoreNonVistList.Count * 100) / jobCount); //Convert.ToInt32((pStoreNonVistList.Count * 100) / jobCount); pJobStatusPercentageList.data.Add(pJobStatusPercentage); } if (pJobStatusPercentageList != null && pJobStatusPercentageList.data != null && pJobStatusPercentageList.data.Count > 0) { ViewBag.VisitPercentage = (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(pJobStatusPercentageList.data); ViewBag.Series = pJobStatusPercentageList.data.Count; ViewBag.Flag = "true"; } #endregion //display UserActivity Graph #region UserActivity Graph Job uJob = new Job(); uJob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null) { GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString())); if (globalUser != null) { //User Activity uJob.AssignedUserGUID = globalUser.UserGUID; } } //FOr Regional Manager if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null) { OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), new Guid(Session["OrganizationGUID"].ToString())); if (OrgUserMap != null) { uJob.RegionGUID = OrgUserMap.RegionGUID; } } if (!string.IsNullOrEmpty(pDayUser)) { if (pDayUser == "Today") { uJob.ActualStartTime = DateTime.UtcNow; uJob.ActualEndTime = DateTime.UtcNow; } if (pDayUser == "7 Days") { uJob.ActualStartTime = DateTime.UtcNow.AddDays(-6); uJob.ActualEndTime = DateTime.UtcNow; } if (pDayUser == "30 Days") { uJob.ActualStartTime = DateTime.UtcNow.AddDays(-30); uJob.ActualEndTime = DateTime.UtcNow; } } ViewBag.Activity = "false"; var userActivityJobList = _IJobRepository.Job_UserActivityGraph(uJob) != null ? _IJobRepository.Job_UserActivityGraph(uJob).ToList() : null; if (userActivityJobList != null && userActivityJobList.Count > 0) { // int i = 0; int arrayCount = 0; int[,] myAL; DateTime pdate = DateTime.Now; if (pDayUser == "Today") { arrayCount = 3; myAL = new int[3, 2]; } else if (pDayUser == "7 Days") { arrayCount = 9; myAL = new int[9, 2]; // pdate = DateTime.Now.AddDays(-7); //pdate = userActivityJobList[0].datevalue; pdate = userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null); } else if (pDayUser == "30 Days") { arrayCount = 32; myAL = new int[32, 2]; //pdate = DateTime.Now.AddDays(-30); //pdate = userActivityJobList[0].datevalue; pdate = userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null); } else { //arrayCount = (int)(userActivityJobList[userActivityJobList.Count - 1].datevalue - userActivityJobList[0].datevalue).TotalDays; arrayCount = (int)((userActivityJobList[userActivityJobList.Count - 1].GetType().GetProperties()[0].GetValue(userActivityJobList[userActivityJobList.Count - 1], null)) - (userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null))).TotalDays; myAL = new int[arrayCount, 2]; //pdate = userActivityJobList[0].datevalue; pdate = userActivityJobList[0].GetType().GetProperties()[0].GetValue(userActivityJobList[0], null); } //foreach (var item in userActivityJobList) for (int i = 0; i < arrayCount; i++) { myAL[i, 0] = i; int binded = 0; for (int j = 0; j < userActivityJobList.Count; j++) { if (pdate.Date == userActivityJobList[j].GetType().GetProperties()[0].GetValue(userActivityJobList[j], null)) { myAL[i, 1] = userActivityJobList[j].GetType().GetProperties()[1].GetValue(userActivityJobList[j], null); binded = 1; } } if (binded == 0) { myAL[i, 1] = 0; } pdate = pdate.AddDays(1); ViewBag.Activity = "true"; } ViewBag.UserActivityList = (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(myAL); } #endregion //ScriptManager.RegisterClientScriptBlock(this, this.Page.GetType(), "function", "", true); #region store non visit List<MarketModel> Marketmodel = new List<MarketModel>(); if (pStoreNonVistList != null && pStoreNonVistList.Count > 0) { if (!string.IsNullOrEmpty(search)) { search = search.ToLower(); pStoreNonVistList = pStoreNonVistList.Where(x => (!String.IsNullOrEmpty(x.RegionName) && x.RegionName.ToLower().Contains(search)) || (!String.IsNullOrEmpty(x.MarketID) && x.MarketID.ToLower().Contains(search)) || (!String.IsNullOrEmpty(x.MarketName) && x.MarketName.ToLower().Contains(search)) ).ToList(); } totalRecord = pStoreNonVistList.ToList().Count; totalPage = (totalRecord / (int)ViewBag.pageCountValue) + ((totalRecord % (int)ViewBag.pageCountValue) > 0 ? 1 : 0); ViewBag.TotalRows = totalRecord; pStoreNonVistList = pStoreNonVistList.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageCountValue)).Take((int)ViewBag.pageCountValue).ToList(); foreach (Market market in pStoreNonVistList) { Marketmodel.Add(ConvertToStoreNonVisit(market)); } } return View(Marketmodel); #endregion } else { // TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','Session Expired');</script>"; return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return RedirectToAction("Login", "User"); } }
public int InsertJobbyPO(Job job) { try { //context.Jobs.Add(job); SqlParameter[] Param = new SqlParameter[29]; Param = SetParametersForPOCreate(job); return context.Database.ExecuteSqlCommand("insert into Jobs(JobGUID,OrganizationGUID,RegionGUID,TerritoryGUID,LocationType,CustomerGUID," + "CustomerStopGUID,ServiceAddress,Latitude,Longitude,AssignedUserGUID,ManagerUserGUID,IsActive,IsDeleted,IsUrgent,StatusCode," + "SubStatusCode,IsSecheduled,JobName,PreferedStartTime,PreferedEndTime,ScheduledStartTime,ActualStartTime," + "JobClass," + "CreateDate,CreateBy,LastModifiedDate,LastModifiedBy,PONumber)" + "values(@pJobGUID,@pOrganizationGUID,@pRegionGUID,@pTerritoryGUID,@pLocationType,@pCustomerGUID," + "@pCustomerStopGUID,@pServiceAddress,@pLatitude,@pLongitude,@pAssignedUserGUID,@pManagerUserGUID,@pIsActive,@pIsDeleted,@pIsUrgent,@pStatusCode," + "@pSubStatusCode,@pIsSecheduled,@pJobName,@pPreferedStartTime,@pPreferedEndTime,@pScheduledStartTime,@pActualStartTime," + "@pJobClass," + "@pCreateDate,@pCreateBy,@pLastModifiedDate,@pLastModifiedBy,@pPONumber)", Param); } catch (Exception ex) { //lretString.Append("InsertJobbyPO Error : " + ex.Message + ""); return 0; } }
// // GET: /StoreVist/ public ActionResult Index(string id = "", string customerid = "", string FromDate = "", string ToDate = "", string Date = "", string selection = "", string RowCount = "", int page = 1, string search = "") { Logger.Debug("Inside CustomerView Controller- Index"); try { ViewBag.CustomerID = customerid; ViewBag.FromDate = FromDate; ViewBag.ToDate = ToDate; ViewBag.Date = Date; int totalPage = 0; int totalRecord = 0; int pCount = 0; if (Session["OrganizationGUID"] != null) { if (!string.IsNullOrEmpty(RowCount)) { int.TryParse(RowCount, out pCount); pageCountList(pCount); } else { pageCountList(pCount); } if (!string.IsNullOrEmpty(Date)) { ViewBag.DateValue = HttpUtility.HtmlDecode(Date); Session["DateValue"] = Date; } else { string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy"); Session["DateValue"] = datevalue; } SiteVisitReports pSiteVisitReports = new SiteVisitReports(); pSiteVisitReports.SiteVisitList = new List<SiteVisit>(); Session["CustomerGUID"] = customerid; if (!string.IsNullOrEmpty(id)) { TempData["TabName"] = id; } else { TempData["TabName"] = "Visits"; } StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder(); sb.Append("<div class='actions'>"); sb.Append("<div class='btn-group'>"); sb1.Append("<div class='actions'>"); sb1.Append("<div class='btn-group'>"); if (!string.IsNullOrEmpty(customerid)) { Place pplace = _IPlaceRepository.GetPlaceByID(new Guid(customerid)); if (pplace != null) { sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pplace.PlaceName + " <i class='icon-angle-down'></i></a>"); sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pplace.PlaceName + " <i class='icon-angle-down'></i></a>"); } } else { 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>"); sb1.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 Client <i class='icon-angle-down'></i></a>"); sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>Select Client <i class='icon-angle-down'></i></a>"); } } sb.Append("<ul id='ulworkgroup' style='height:100px;overflow-y:scroll' class='dropdown-menu pull-right'>"); sb1.Append("<ul id='ulworkgroup' style='height:100px;overflow-y:scroll' class='dropdown-menu pull-right'>"); if (string.IsNullOrEmpty(selection) || selection != "All") { //sb.Append("<li><a href=" + Url.Action("Index", new { id = "Visits", selection = "All" }) + ">All</a></li>"); //sb1.Append("<li><a href=" + Url.Action("Index", new { id = "Non-Visits", selection = "All" }) + ">All</a></li>"); sb.Append("<li><a onclick=\"RedirectAction('');\">All</a></li>"); sb1.Append("<li><a onclick=\"RedirectAction('');\">All</a></li>"); } List<Place> PlaceList = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList(); foreach (Place item in PlaceList) { sb.Append("<li><a onclick=\"RedirectAction('" + item.PlaceGUID.ToString() + "');\" data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>"); sb1.Append("<li><a onclick=\"RedirectAction('" + item.PlaceGUID.ToString() + "');\" data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>"); } sb.Append("</ul>"); sb.Append("</div>"); sb.Append("</div>"); sb1.Append("</ul>"); sb1.Append("</div>"); sb1.Append("</div>"); ViewBag.CustomerListVisit = sb.ToString(); ViewBag.CustomerListNonVisit = sb1.ToString(); Job ljob = new Job(); ljob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); if (!string.IsNullOrEmpty(customerid)) ljob.CustomerGUID = new Guid(customerid); DateTime From, To, Datecontent; if (!string.IsNullOrEmpty(FromDate) && ParseExact(FromDate, "dd-MM-yyyy", out From)) { ljob.PreferedStartTime = From; } else { ljob.PreferedStartTime = DateTime.Now.AddDays(-29); } if (!string.IsNullOrEmpty(ToDate) && ParseExact(ToDate, "dd-MM-yyyy", out To)) { ljob.PreferedEndTime = To; } else { ljob.PreferedEndTime = DateTime.Now; } ljob.JobName = "Store Visit"; //FOr Regional Manager if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null) { OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), ljob.OrganizationGUID); if (OrgUserMap != null) { ljob.RegionGUID = OrgUserMap.RegionGUID; } } //check the current user is Field Manager or not if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null) { GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString())); if (globalUser != null) { ljob.AssignedUserGUID = globalUser.UserGUID; } } List<Job> lsitevisit = _IJobRepository.GetSiteVisitJobs(ljob); if (lsitevisit != null && lsitevisit.Count > 0) { ViewBag.Search = search; if (!string.IsNullOrEmpty(search)) { search = search.ToLower(); lsitevisit = lsitevisit.Where( p => (!String.IsNullOrEmpty(_IRegionRepository.GetRegionNameByRegionGUID(new Guid(p.RegionGUID.ToString()))) && _IRegionRepository.GetRegionNameByRegionGUID(new Guid(p.RegionGUID.ToString())).ToLower().Contains(search)) || (!String.IsNullOrEmpty(p.JobName) && p.JobName.ToLower().StartsWith(search)) || (!String.IsNullOrEmpty(p.PONumber) && p.PONumber.ToLower().StartsWith(search)) || (!String.IsNullOrEmpty(_IJobRepository.GetStatusName((int)p.StatusCode)) && _IJobRepository.GetStatusName((int)p.StatusCode).ToLower().Contains(search))).ToList(); } totalRecord = lsitevisit.ToList().Count; totalPage = (totalRecord / (int)ViewBag.pageCountValue) + ((totalRecord % (int)ViewBag.pageCountValue) > 0 ? 1 : 0); ViewBag.TotalRows = totalRecord; lsitevisit = lsitevisit.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageCountValue)).Take((int)ViewBag.pageCountValue).ToList(); foreach (Job job in lsitevisit) { SiteVisit _siteVisit = ConvertToSiteVisit(job); if (_siteVisit != null) { pSiteVisitReports.SiteVisitList.Add(_siteVisit); } } } else ViewBag.TotalRows = 0; Session["SiteVisit"] = pSiteVisitReports.SiteVisitList; if (!string.IsNullOrEmpty(RowCount)) ViewBag.pageCountValue = int.Parse(RowCount); else ViewBag.pageCountValue = 5; return View(pSiteVisitReports); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return RedirectToAction("Login", "User"); } }
//public void AssignUser(Guid UserGUID, Guid JobIndexGUID) //{ // using (var dataContext = new WorkersInMotionJobDB()) // { // var qry = from p in dataContext.Jobs where p.JobGUID == JobIndexGUID select p; // var item = qry.Single(); // item.AssignedUserGUID = UserGUID; // item.ActialStartTime = DateTime.UtcNow; // item.ActualEndTime = DateTime.UtcNow.AddDays(1); // item.PreferedEndTime = DateTime.UtcNow; // item.PreferedStartTime = DateTime.UtcNow; // item.StatusCode = 2; // dataContext.SaveChanges(); // } //} public int UpdateJobFromClient(Job job) { //using (var dataContext = new WorkersInMotionDB()) //{ // var qry = from p in dataContext.Jobs where p.JobGUID == job.JobGUID select p; // var item = qry.Single(); // item.StatusCode = job.StatusCode; // item.ActualStartTime = job.ActualStartTime; // return dataContext.SaveChanges(); //} SqlParameter[] Param = new SqlParameter[3]; Param[0] = new SqlParameter("@pStatusCode", SqlDbType.Int); Param[0].Value = job.StatusCode; Param[1] = new SqlParameter("@pActualStartTime", SqlDbType.DateTime); Param[1].Value = job.ActualStartTime; Param[2] = new SqlParameter("@pJobGUID", SqlDbType.UniqueIdentifier); Param[2].Value = job.JobGUID; return context.Database.ExecuteSqlCommand("update Jobs set StatusCode=@pStatusCode,ActualStartTime=@pActualStartTime where JobGUID=@pJobGUID", Param); }
// // GET: /StoreVist/ public ActionResult Index(string id = "", string customerid = "", string FromDate = "", string ToDate = "", string Date = "", string selection = "", string LastModifiedDate = "", string Visit_RowCount = "", string NonVisit_RowCount = "", int page = 1, string Visit_Search = "", string NonVisit_Search = "", string hdnrecordsize="") { Logger.Debug("Inside CustomerView Controller- Index"); try { ViewBag.CustomerID = customerid; ViewBag.FromDate = FromDate; ViewBag.ToDate = ToDate; ViewBag.Date = Date; int visit_TotalPage = 0; int visit_TotalRecord = 0; int visit_pCount = 0; int nonvisit_TotalPage = 0; int nonvisit_TotalRecord = 0; int nonvisit_pCount = 0; if (Session["OrganizationGUID"] != null) { if (!string.IsNullOrEmpty(Visit_RowCount)) { int.TryParse(Visit_RowCount, out visit_pCount); pageVisitCountList(visit_pCount); } else { pageVisitCountList(visit_pCount); } if (!string.IsNullOrEmpty(NonVisit_RowCount)) { int.TryParse(NonVisit_RowCount, out nonvisit_pCount); pageNonVisitCountList(nonvisit_pCount); } else { pageNonVisitCountList(nonvisit_pCount); } if (!string.IsNullOrEmpty(Date)) { ViewBag.DateValue = HttpUtility.HtmlDecode(Date); Session["DateValue"] = Date; } else if (!string.IsNullOrEmpty(LastModifiedDate)) { Logger.Debug("Inside Last Modfied dislay"); if (!string.IsNullOrEmpty(FromDate) && !string.IsNullOrEmpty(ToDate)) { DateTime pFrom = new DateTime(), pTo = new DateTime(); if (ParseExact(FromDate, "dd-MM-yyyy", out pFrom)) { ParseExact(ToDate, "dd-MM-yyyy", out pTo); Logger.Debug("Inside"); string datevalue = pFrom.ToString("MMMM d, yyyy") + " - " + pTo.ToString("MMMM d, yyyy"); ViewBag.DateValue = datevalue; Session["DateValue"] = datevalue; } else { Logger.Debug("OutSide"); string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy"); ViewBag.DateValue = datevalue; Session["DateValue"] = datevalue; } Logger.Debug("From Parst : " + pFrom); Logger.Debug("To Parse : " + pTo); } else { Logger.Debug("OutSide1"); string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy"); ViewBag.DateValue = datevalue; Session["DateValue"] = datevalue; } } else { Logger.Error("OutSide2"); string datevalue = DateTime.Now.AddDays(-29).ToString("MMMM d, yyyy") + " - " + DateTime.Now.ToString("MMMM d, yyyy"); ViewBag.DateValue = datevalue; Session["DateValue"] = datevalue; } StoreVisitReports pStoreVisitReports = new StoreVisitReports(); pStoreVisitReports.StoreVisitList = new List<StoreVisit>(); pStoreVisitReports.StoreNonVisitList = new List<MarketModel>(); Session["CustomerGUID"] = customerid; if (!string.IsNullOrEmpty(id)) { TempData["TabName"] = id; } else { TempData["TabName"] = "Visits"; } StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder(); sb.Append("<div class='actions'>"); sb.Append("<div class='btn-group'>"); sb1.Append("<div class='actions'>"); sb1.Append("<div class='btn-group'>"); if (!string.IsNullOrEmpty(customerid)) { Place pplace = _IPlaceRepository.GetPlaceByID(new Guid(customerid)); if (pplace != null) { Session["ClientCompanyName"] = pplace.PlaceName; sb.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pplace.PlaceName + " <i class='icon-angle-down'></i></a>"); sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>" + pplace.PlaceName + " <i class='icon-angle-down'></i></a>"); } } else { 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>"); sb1.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 Client <i class='icon-angle-down'></i></a>"); sb1.Append("<a href='#' id='ulaworkergroup' class='btn green' data-toggle='dropdown'><i class='icon-map-marker'></i>Select Client <i class='icon-angle-down'></i></a>"); } } sb.Append("<ul id='ulworkgroup' style='height:100px;overflow-y:scroll' class='dropdown-menu pull-right'>"); sb1.Append("<ul id='ulworkgroup' style='height:100px;overflow-y:scroll' class='dropdown-menu pull-right'>"); if (string.IsNullOrEmpty(selection) || selection != "All") { //sb.Append("<li><a href=" + Url.Action("Index", new { id = "Visits", selection = "All" }) + ">All</a></li>"); //sb1.Append("<li><a href=" + Url.Action("Index", new { id = "Non-Visits", selection = "All" }) + ">All</a></li>"); sb.Append("<li><a onclick=\"RedirectAction('Visits','');\">All</a></li>"); sb1.Append("<li><a onclick=\"RedirectAction('NonVisits','');\">All</a></li>"); } List<Place> PlaceList = _IPlaceRepository.GetPlaceByOrganizationGUID(new Guid(Session["OrganizationGUID"].ToString())).ToList(); foreach (Place item in PlaceList) { //sb.Append("<li><a href=" + Url.Action("Index", new { id = "Visits", customerid = item.PlaceGUID.ToString() }) + " data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>"); //sb1.Append("<li><a href=" + Url.Action("Index", new { id = "Non-Visits", customerid = item.PlaceGUID.ToString() }) + " data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>"); sb.Append("<li><a onclick=\"RedirectAction('Visits','" + item.PlaceGUID.ToString() + "');\" data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>"); sb1.Append("<li><a onclick=\"RedirectAction('NonVisits','" + item.PlaceGUID.ToString() + "');\" data-groupguid=" + item.PlaceGUID + ">" + item.PlaceName + "</a></li>"); } sb.Append("</ul>"); sb.Append("</div>"); sb.Append("</div>"); sb1.Append("</ul>"); sb1.Append("</div>"); sb1.Append("</div>"); ViewBag.CustomerListVisit = sb.ToString(); ViewBag.CustomerListNonVisit = sb1.ToString(); Market _market = new Market(); Job ljob = new Job(); ljob.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); _market.OrganizationGUID = new Guid(Session["OrganizationGUID"].ToString()); if (!string.IsNullOrEmpty(customerid)) { _market.OwnerGUID = new Guid(customerid); ljob.CustomerGUID = new Guid(customerid); } DateTime From, To, Datecontent, LModifiedDate; //LastModifiedDate = _IUserRepository.DecodeFrom64(LastModifiedDate); if (!string.IsNullOrEmpty(LastModifiedDate) && ParseExact(LastModifiedDate, "dd-MM-yyyy", out LModifiedDate)) { ljob.LastModifiedDate = LModifiedDate; _market.LastStoreVisitedDate = LModifiedDate; } else if (!string.IsNullOrEmpty(FromDate) && ParseExact(FromDate, "dd-MM-yyyy", out From)) _market.LastStoreVisitedDate = From; else _market.LastStoreVisitedDate = DateTime.Now.AddDays(-29); if (!string.IsNullOrEmpty(FromDate) && ParseExact(FromDate, "dd-MM-yyyy", out From)) { ljob.ActualStartTime = From; } else { Logger.Error("From Else"); ljob.ActualStartTime = DateTime.Now.AddDays(-29); } if (!string.IsNullOrEmpty(ToDate) && ParseExact(ToDate, "dd-MM-yyyy", out To)) { ljob.ActualEndTime = To; } else { Logger.Error("To Else"); ljob.ActualEndTime = DateTime.Now; } ljob.JobName = "Store Visit"; Logger.Debug("Job Object" + Newtonsoft.Json.JsonConvert.SerializeObject(ljob)); //FOr Regional Manager if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U_RM" && Session["UserGUID"] != null) { OrganizationUsersMap OrgUserMap = _IOrganizationRepository.GetOrganizationUserMapByUserGUID(new Guid(Session["UserGUID"].ToString()), ljob.OrganizationGUID); if (OrgUserMap != null) { ljob.RegionGUID = OrgUserMap.RegionGUID; _market.RegionGUID = OrgUserMap.RegionGUID; } } //check the current user is Field Manager or not if (Session["UserType"] != null && !string.IsNullOrEmpty(Session["UserType"].ToString()) && Session["UserType"].ToString() == "ENT_U" && Session["UserGUID"] != null) { GlobalUser globalUser = _IGlobalUserRepository.GetGlobalUserByID(new Guid(Session["UserGUID"].ToString())); if (globalUser != null) { ljob.AssignedUserGUID = globalUser.UserGUID; _market.FMUserID = globalUser.USERID; } } List<Job> lstorevisit = _IJobRepository.GetStoreVisitJobs(ljob); List<Market> lstorenonvisit = new List<Market>(); lstorenonvisit = _IMarketRepository.GetStoreNonVisit(_market); if (lstorevisit != null && lstorevisit.Count > 0) { ViewBag.Visit_Search = Visit_Search; if (!string.IsNullOrEmpty(Visit_Search)) { Visit_Search = Visit_Search.ToLower(); lstorevisit = lstorevisit.Where( p => (!String.IsNullOrEmpty(_IRegionRepository.GetRegionNameByRegionGUID(new Guid(p.RegionGUID.ToString()))) && _IRegionRepository.GetRegionNameByRegionGUID(new Guid(p.RegionGUID.ToString())).ToLower().Contains(Visit_Search)) || (!String.IsNullOrEmpty(p.CustomerStopGUID.ToString()) && _IMarketRepository.GetMarketByID(new Guid(p.CustomerStopGUID.ToString())).MarketID.ToLower().Contains(Visit_Search)) || (!String.IsNullOrEmpty(p.PONumber) && _IMarketRepository.GetMarketByCustomerID(p.OrganizationGUID, _IPORepository.GetPObyPoNumber(p.PONumber).PlaceID, _IPORepository.GetPObyPoNumber(p.PONumber).MarketID).MarketID.ToLower().Contains(Visit_Search)) || (!String.IsNullOrEmpty(p.CustomerStopGUID.ToString()) && _IMarketRepository.GetMarketByID(new Guid(p.CustomerStopGUID.ToString())).MarketName.ToLower().Contains(Visit_Search)) || (!String.IsNullOrEmpty(p.PONumber) && _IMarketRepository.GetMarketByCustomerID(p.OrganizationGUID, _IPORepository.GetPObyPoNumber(p.PONumber).PlaceID, _IPORepository.GetPObyPoNumber(p.PONumber).MarketID).MarketName.ToLower().Contains(Visit_Search)) || (!String.IsNullOrEmpty(_IJobRepository.GetStatusName((int)p.StatusCode)) && _IJobRepository.GetStatusName((int)p.StatusCode).ToLower().Contains(Visit_Search)) || (!String.IsNullOrEmpty(_IUserProfileRepository.GetUserProfileByUserID(_IGlobalUserRepository.GetGlobalUserByID(new Guid(p.ManagerUserGUID.ToString())).UserGUID, p.OrganizationGUID).ToString()) && _IUserProfileRepository.GetUserProfileByUserID(_IGlobalUserRepository.GetGlobalUserByID(new Guid(p.ManagerUserGUID.ToString())).UserGUID, p.OrganizationGUID).ToString().ToLower().Contains(Visit_Search))).ToList(); } visit_TotalRecord = lstorevisit.ToList().Count; visit_TotalPage = (visit_TotalRecord / (int)ViewBag.pageVisitCountValue) + ((visit_TotalRecord % (int)ViewBag.pageVisitCountValue) > 0 ? 1 : 0); ViewBag.Visit_TotalRows = visit_TotalRecord; lstorevisit = lstorevisit.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageVisitCountValue)).Take((int)ViewBag.pageVisitCountValue).ToList(); foreach (Job job in lstorevisit) { StoreVisit storevisit = ConvertToStoreVisit(job); if (storevisit != null) { pStoreVisitReports.StoreVisitList.Add(storevisit); } } } // Logger.Debug("Store Non Visit Count : " + lstorenonvisit.Count); if (lstorenonvisit != null && lstorenonvisit.Count > 0) { ViewBag.NonVisit_Search = NonVisit_Search; if (!string.IsNullOrEmpty(NonVisit_Search)) { NonVisit_Search = NonVisit_Search.ToLower(); lstorenonvisit = lstorenonvisit.Where( p => (!String.IsNullOrEmpty(p.RegionName) && p.RegionName.ToLower().Contains(NonVisit_Search)) || (!String.IsNullOrEmpty(p.MarketID) && p.MarketID.ToLower().Contains(NonVisit_Search)) || (!String.IsNullOrEmpty(p.MarketName) && p.MarketName.ToLower().Contains(NonVisit_Search))).ToList(); } nonvisit_TotalRecord = lstorenonvisit.ToList().Count; nonvisit_TotalPage = (nonvisit_TotalRecord / (int)ViewBag.pageNonCountValue) + ((nonvisit_TotalRecord % (int)ViewBag.pageNonCountValue) > 0 ? 1 : 0); ViewBag.NonVisit_TotalRows = nonvisit_TotalRecord; lstorenonvisit = lstorenonvisit.OrderBy(a => a.OrganizationGUID).Skip(((page - 1) * (int)ViewBag.pageNonCountValue)).Take((int)ViewBag.pageNonCountValue).ToList(); foreach (Market market in lstorenonvisit) { MarketModel _marketModel = ConvertToStoreNonVisit(market); if (_marketModel != null) { pStoreVisitReports.StoreNonVisitList.Add(_marketModel); } } } Session["StoreVisit"] = pStoreVisitReports.StoreVisitList; Session["StoreNonVisit"] = pStoreVisitReports.StoreNonVisitList; if (!string.IsNullOrEmpty(Visit_RowCount)) ViewBag.pageVisitCountValue = int.Parse(Visit_RowCount); else ViewBag.pageVisitCountValue = 5; if (!string.IsNullOrEmpty(NonVisit_RowCount)) ViewBag.pageNonCountValue = int.Parse(NonVisit_RowCount); else ViewBag.pageNonCountValue = 5; bool visit = false; bool nonvisit = false; if (null != Request && System.Text.RegularExpressions.Regex.IsMatch(Request.Url.ToString().Replace("-", ""), string.Format(@"\b{0}\b", "Visits"))) visit = true; if (null != Request && System.Text.RegularExpressions.Regex.IsMatch(Request.Url.ToString().Replace("-", ""), string.Format(@"\b{0}\b", "NonVisits"))) nonvisit = true; if (visit) TempData["TabName"] = "Visits"; else if(nonvisit) TempData["TabName"] = "Non-Visits"; return View(pStoreVisitReports); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return RedirectToAction("Login", "User"); } }
public int UpdateJob(Job job) { // context.Entry(job).State = EntityState.Modified; SqlParameter[] Param = new SqlParameter[46]; Param = SetParameters(job); return context.Database.ExecuteSqlCommand("update Job set JobReferenceNo=@pJobReferenceNo,OrganizationGUID=@pOrganizationGUID," + "RegionGUID=@pRegionGUID,TerritoryGUID=@pTerritoryGUID,LocationType=@pLocationType,CustomerGUID=@pCustomerGUID," + "CustomerStopGUID=@pCustomerStopGUID,ServicePointGUID=@pServicePointGUID,ServiceAddress=@pServiceAddress,Latitude=@pLatitude,Longitude=@pLongitude," + "AssignedUserGUID=@pAssignedUserGUID,ManagerUserGUID=@pManagerUserGUID,IsActive=@pIsActive,IsDeleted=@pIsDeleted,IsUrgent=@pIsUrgent,StatusCode=@pStatusCode," + "SubStatusCode=@pSubStatusCode,IsSecheduled=@pIsSecheduled,JobName=@pJobName,PreferedStartTime=@pPreferedStartTime,PreferedEndTime=@pPreferedEndTime," + "ScheduledStartTime=@pScheduledStartTime,ScheduledEndTime=@pScheduledEndTime,ActualStartTime=@pActualStartTime`,ActualEndTime=@pActualEndTime," + "EstimatedDuration=@pEstimatedDuration,QuotedDuration=@pQuotedDuration,ActualDuration=@pActualDuration,CostType=@pCostType," + "QuotedCost=@pQuotedCost,ActualCost=@pActualCost,JobForm=@pJobForm,JobClass=@pJobClass,SignOffRequired=@pSignOffRequired,SignoffName=@pSignoffName,PictureRequired=@pPictureRequired," + "PictureDescription=@pPictureDescription,LocationSpecific=@pLocationSpecific,PONumber=@pPONumber,TermsURL=@pTermsURL,CreateDate=@pCreateDate," + "CreateBy=@pCreateBy,LastModifiedDate=@pLastModifiedDate,LastModifiedBy=@pLastModifiedBy where JobGUID=@pJobGUID", Param); }
public ActionResult GeneratePDF(string pdfcontent) { Logger.Debug("Inside Store Visit Controller- GeneratePDF"); try { if (Session["OrganizationGUID"] != null) { if (!string.IsNullOrEmpty(pdfcontent.ToString())) { Response.ContentType = "application/pdf"; Response.Cache.SetCacheability(HttpCacheability.NoCache); StringBuilder pVisit = new StringBuilder(); // pVisit.Append("<header>Prabhu</header>"); //pVisit.Append("<html>"); //pVisit.Append("<head>"); //pVisit.Append("<title></title>"); //pVisit.Append("</head>"); //pVisit.Append("<body>"); pVisit.Append("<div>"); pVisit.Append("<table style='clear:both;width:100%;border-spacing: 0px;border-color:black;color: black;border-collapse: collapse;font-family: verdana;font-size: 10px;border:1px solid black;' border='1' cellpadding='8'>"); pVisit.Append("<thead>"); if (pdfcontent == "StoreVisit" && Session["StoreVisit"] != null) { Session["VisitType"] = "Store Visit Report"; Response.AddHeader("content-disposition", "attachment;filename=Visits.pdf"); pVisit.Append("<tr>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Region</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store ID</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store Name</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Visit Date</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Status</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Field Manager</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Details</td>"); pVisit.Append("</tr>"); pVisit.Append("</thead>"); pVisit.Append("<tbody>"); List<StoreVisit> visit = new List<StoreVisit>(); visit = (List<StoreVisit>)Session["StoreVisit"]; if (visit.Count > 0) { foreach (StoreVisit item in visit) { pVisit.Append("<tr>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.RegionName + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.MarketID + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.CustomerStopName + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.Date + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.Status + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.FMName + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'><a href='#" + item.JobGUID.ToString() + "'>Detail</a></td>"); //pVisit.Append("<a href='#'>Detail</a>"); pVisit.Append("</tr>"); } } else { TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>"; return RedirectToAction("Index", "StoreVisit", new { id = "Visits" }); } } else if (pdfcontent == "StoreNonVisit" && Session["StoreNonVisit"] != null) { Session["VisitType"] = "Store Non-Visit Report"; Response.AddHeader("content-disposition", "attachment;filename=NonVisits.pdf"); pVisit.Append("<tr>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Region</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store ID</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Store Name</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Last Visit Date</td>"); //pVisit.Append("<td style='font-weight:bold;font-size:10px;font-family:verdana'>Status</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Field Manager</td>"); pVisit.Append("<td style='font-weight:bold;font-size:10px;border-color:black;font-family:verdana'>Details</td>"); pVisit.Append("</tr>"); pVisit.Append("</thead>"); pVisit.Append("<tbody>"); List<MarketModel> nonvisit = new List<MarketModel>(); nonvisit = (List<MarketModel>)Session["StoreNonVisit"]; if (nonvisit.Count > 0) { foreach (MarketModel item in nonvisit) { pVisit.Append("<tr>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.RegionName + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.MarketID + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.MarketName + "</td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.LastStoreVisitedDate + "</td>"); //pVisit.Append("<td style='font-size:8px;font-family:verdana'></td>"); pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'>" + item.FirstName + " " + item.LastName + "</td>"); Job _jobnew = _IJobRepository.GetJobByCustomerStopGUID(new Guid(item.MarketGUID)); if (_jobnew != null) { pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'><a href='#" + item.MarketGUID.ToString() + "'>Detail</a></td>"); } else { pVisit.Append("<td style='font-size:8px;border-color:black;font-family:verdana'></td>"); } pVisit.Append("</tr>"); } } else { TempData["msg"] = "<script>ModalPopupsAlert('Workers-In-Motion','No data to generate PDF');</script>"; return RedirectToAction("Index", "StoreVisit", new { id = "Non-Visits" }); } } else { pVisit.Append("<tr>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Region</td>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Store ID</td>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Store Name</td>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Visit Date</td>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Status</td>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Field Manager</td>"); pVisit.Append("<td style='font-weight:bold;border-color:black;font-size:10px;font-family:verdana'>Details</td>"); pVisit.Append("</tr>"); pVisit.Append("</thead>"); pVisit.Append("<tbody>"); } pVisit.Append("</tbody>"); pVisit.Append("</table>"); pVisit.Append("</div>"); if (pdfcontent == "StoreVisit" && Session["StoreVisit"] != null) { List<StoreVisit> visit = new List<StoreVisit>(); visit = (List<StoreVisit>)Session["StoreVisit"]; if (visit.Count > 0) { List<string> jobNameList = new List<string>(); foreach (StoreVisit item in visit) { JobFormNew pJobFormView = new JobFormNew(); Job _job = new Job(); _job = _IJobRepository.GetJobByID(item.JobGUID); if (_job != null) { ViewBag.JobName = _job.JobName; if (!jobNameList.Contains(_job.JobGUID.ToString())) { jobNameList.Add(_job.JobGUID.ToString()); if (!string.IsNullOrEmpty(_job.JobForm)) { pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString()); } if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0) { pJobFormView.FormValues.OrderBy(x => x.ControlID); // pVisit.Append(GetJobFormHTMLForStoreVisit(pJobFormView, _job.JobName, _job.JobGUID.ToString(), _job.CustomerStopGUID.ToString(), _job.JobGUID.ToString(), _job.StatusCode != null ? Convert.ToInt32(_job.StatusCode) : 6)); } } } } } } else if (pdfcontent == "StoreNonVisit" && Session["StoreNonVisit"] != null) { List<MarketModel> nonvisit = new List<MarketModel>(); nonvisit = (List<MarketModel>)Session["StoreNonVisit"]; if (nonvisit.Count > 0) { List<string> jobNameList = new List<string>(); foreach (MarketModel item in nonvisit) { JobFormNew pJobFormView = new JobFormNew(); Job _job = new Job(); Market _market = _IMarketRepository.GetMarketByID(new Guid(item.MarketGUID)); if (_market != null) { _job = _IJobRepository.GetJobByCustomerStopGUID(new Guid(item.MarketGUID)); if (_job != null) { ViewBag.JobName = _job.JobName; if (!jobNameList.Contains(_job.CustomerStopGUID.ToString())) { jobNameList.Add(_job.CustomerStopGUID.ToString()); if (!string.IsNullOrEmpty(_job.JobForm)) { pJobFormView = JobFormJsonConvert(_job.JobForm, "PDFImageURL", _job.JobGUID.ToString()); } if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0) { pJobFormView.FormValues.OrderBy(x => x.ControlID); // pVisit.Append(GetJobFormHTMLForStoreNonVisit(pJobFormView, _job.JobName, _job.CustomerStopGUID.ToString(), _job.CustomerGUID.ToString(), _job.StatusCode != null ? Convert.ToInt32(_job.StatusCode) : 6)); } } } } } } } //pVisit.Append("</body>"); //pVisit.Append("</html>"); //byte[] byteArray = Encoding.UTF8.GetBytes(pVisit.ToString()); //MemoryStream ms = new MemoryStream(byteArray); //Stream stream = ms; //StreamReader sr = new StreamReader(stream); ////Document document = new Document(new Rectangle(288f, 144f), 10f, 10f, 30f, 30f); //Document document = new Document(); //FileStream fs = new FileStream(Request.PhysicalApplicationPath + "\\StoreVisit.pdf", FileMode.Create); //PdfWriter writer = PdfWriter.GetInstance(document, fs); Document document = new Document(PageSize.A4, 70, 55, 40, 25); PdfWriter writer = PdfWriter.GetInstance(document, System.Web.HttpContext.Current.Response.OutputStream); writer.PageEvent = new PDFFooter(); document.Open(); TextReader txtReader = new StringReader(pVisit.ToString()); var xmlWorkerHelper = XMLWorkerHelper.GetInstance(); xmlWorkerHelper.ParseXHtml(writer, document, txtReader); //iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document); //hw.Parse(sr); document.Close(); //Response.ContentType = "application/pdf"; ////Set default file Name as current datetime //Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToString("yyyyMMdd") + ".pdf"); System.Web.HttpContext.Current.Response.Write(document); Response.Flush(); Response.End(); //WebClient client = new WebClient(); //Byte[] buffer = client.DownloadData(Request.PhysicalApplicationPath + "\\StoreVisit.pdf"); //return File(buffer, "application/pdf"); } } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); } return null; }
public IEnumerable<dynamic> Job_UserActivityGraph(Job pJob) { try { //using (var dataContext = new WorkersInMotionDB()) //{ // //List<Job> joblist = (from p in dataContext.Jobs // // where // // (pJob.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pJob.OrganizationGUID) // // && (pJob.CustomerGUID == null || pJob.CustomerGUID == Guid.Empty || p.CustomerGUID == pJob.CustomerGUID) // // && (pJob.RegionGUID == null || pJob.RegionGUID == Guid.Empty || p.RegionGUID == pJob.RegionGUID) // // && (pJob.TerritoryGUID == null || pJob.TerritoryGUID == Guid.Empty || p.TerritoryGUID == pJob.TerritoryGUID) // // && (pJob.AssignedUserGUID == null || pJob.AssignedUserGUID == Guid.Empty || p.AssignedUserGUID == pJob.AssignedUserGUID) // // //&& ((p.PreferedStartTime == null || (p.PreferedStartTime != null && Convert.ToDateTime(p.PreferedStartTime.Value.Date).Date >= pJob.PreferedStartTime.Value.Date)) && (p.PreferedEndTime == null || (p.PreferedEndTime != null && Convert.ToDateTime(p.PreferedEndTime.Value.Date).Date <= pJob.PreferedEndTime.Value.Date))) // // && p.IsDeleted == false && p.StatusCode != 1 // // && p.JobName == "Store Visit" // // select p).OrderBy(x => x.ScheduledStartTime).ToList(); // SqlParameter[] Param = new SqlParameter[46]; // Param = SetParameters(pJob); // List<Job> joblist = context.Database.SqlQuery<Job>("select * from Jobs where" // + "(OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (CustomerGUID=@pCustomerGUID OR @pCustomerGUID is NULL or @pCustomerGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "AND (TerritoryGUID=@pTerritoryGUID OR @pTerritoryGUID is NULL or @pTerritoryGUID=(cast(cast(0 as binary) as uniqueidentifier)))" // + "and IsDeleted=0 and StatusCode!=1 and JobName='Store Visit' Order by ScheduledStartTime", Param).ToList(); // if (joblist != null && joblist.Count > 0) // { // if (pJob.ActualStartTime != null && pJob.ActualEndTime != null) // joblist = joblist.Where(p => (p.ActualStartTime == null || (p.ActualStartTime != null && Convert.ToDateTime(p.ActualStartTime.Value.Date).Date >= pJob.ActualStartTime.Value.Date)) && (p.ActualEndTime == null || (p.ActualEndTime != null && Convert.ToDateTime(p.ActualEndTime.Value.Date).Date <= pJob.ActualEndTime.Value.Date))).ToList(); // var groups = joblist.GroupBy(item => new { Convert.ToDateTime(item.CreateDate.Value.Date).Date }).Select(item => new // { // datevalue = item.Key.Date, // count = item.Count() // }).ToList(); // return groups; // } // else // return null; // //var joblist = (from p in dataContext.Jobs // // where (pJob.OrganizationGUID == Guid.Empty || p.OrganizationGUID == pJob.OrganizationGUID) // // && (pJob.AssignedUserGUID == null || pJob.AssignedUserGUID == Guid.Empty || p.AssignedUserGUID == pJob.AssignedUserGUID) // // && (pJob.RegionGUID == null || pJob.RegionGUID == Guid.Empty || p.RegionGUID == pJob.RegionGUID) // // && p.IsDeleted == false // // && p.StatusCode != 1 // // select p).OrderBy(x => x.CreateDate).ToList(); // //if (joblist != null && joblist.Count > 0) // //{ // // if (pJob.ActualStartTime != null && pJob.ActualEndTime != null) // // joblist = joblist.Where(p => (p.ActualStartTime == null || (p.ActualStartTime != null && Convert.ToDateTime(p.ActualStartTime.Value.Date).Date >= pJob.ActualStartTime.Value.Date)) && (p.ActualEndTime == null || (p.ActualEndTime != null && Convert.ToDateTime(p.ActualEndTime.Value.Date).Date <= pJob.ActualEndTime.Value.Date))).ToList(); // //} //} //SqlParameter[] Param = new SqlParameter[46]; //Param = SetParameters(pJob); SqlParameter[] Param = new SqlParameter[4]; Param[0] = new SqlParameter("@pOrganizationGUID", SqlDbType.UniqueIdentifier); Param[0].Value = pJob.OrganizationGUID; Param[1] = new SqlParameter("@pCustomerGUID", SqlDbType.UniqueIdentifier); Param[1].Value = (object)pJob.CustomerGUID ?? DBNull.Value; Param[2] = new SqlParameter("@pRegionGUID", SqlDbType.UniqueIdentifier); Param[2].Value = (object)pJob.RegionGUID ?? DBNull.Value; Param[3] = new SqlParameter("@pTerritoryGUID", SqlDbType.UniqueIdentifier); Param[3].Value = (object)pJob.TerritoryGUID ?? DBNull.Value; List<Job> joblist = context.Database.SqlQuery<Job>("select * from Jobs where" + "(OrganizationGUID=@pOrganizationGUID OR @pOrganizationGUID is NULL or @pOrganizationGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (CustomerGUID=@pCustomerGUID OR @pCustomerGUID is NULL or @pCustomerGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (RegionGUID=@pRegionGUID OR @pRegionGUID is NULL or @pRegionGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " AND (TerritoryGUID=@pTerritoryGUID OR @pTerritoryGUID is NULL or @pTerritoryGUID=(cast(cast(0 as binary) as uniqueidentifier)))" + " and IsDeleted=0 and StatusCode!=1 and JobName='Store Visit' Order by ScheduledStartTime", Param).ToList(); if (joblist != null && joblist.Count > 0) { if (pJob.ActualStartTime != null && pJob.ActualEndTime != null) joblist = joblist.Where(p => (p.ActualStartTime == null || (p.ActualStartTime != null && Convert.ToDateTime(p.ActualStartTime.Value.Date).Date >= pJob.ActualStartTime.Value.Date)) && (p.ActualEndTime == null || (p.ActualEndTime != null && Convert.ToDateTime(p.ActualEndTime.Value.Date).Date <= pJob.ActualEndTime.Value.Date))).ToList(); var groups = joblist.GroupBy(item => new { Convert.ToDateTime(item.CreateDate.Value.Date).Date }).Select(item => new { datevalue = item.Key.Date, count = item.Count() }).ToList(); return groups; } else return null; } catch (Exception exception) { return null; } }
public ActionResult JobForm(string id = "", string type = "") { Logger.Debug("Inside Job Controller- View Job"); try { if (Session["OrganizationGUID"] != null) { ViewBag.Type = type; Job _job = new Job(); JobFormNew pJobFormView = new JobFormNew(); if (!string.IsNullOrEmpty(type) && type == "Visit") { _job = _IJobRepository.GetJobByID(new Guid(id)); //pJobFormView.JobGUID = id; if (_job != null) { ViewBag.JobName = _job.JobName; } } else { Market _market = _IMarketRepository.GetMarketByID(new Guid(id)); if (_market != null) { _job = _IJobRepository.GetJobByCustomerStopGUID(new Guid(id)); if (_job != null) { ViewBag.JobName = _job.JobName; } } } if (_job != null && !string.IsNullOrEmpty(_job.JobForm)) { pJobFormView = JobFormJsonConvert(_job.JobForm, "ImageURL", _job.JobGUID.ToString()); } if (pJobFormView != null && pJobFormView.FormValues != null && pJobFormView.FormValues.Count > 0) { JobFormHeading JobFormHeading = GetJobFormDetails(_job); if (JobFormHeading != null) { pJobFormView.JobFormHeading = JobFormHeading; } else { JobFormHeading = null; } pJobFormView.JobFormHeading = JobFormHeading; pJobFormView.FormValues.OrderBy(x => x.ControlID); } return View(pJobFormView); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); if (Session["UserType"] != null && Session["UserType"].ToString() != "ENT_A") return RedirectToAction("../JobStatus/Index"); else return RedirectToAction("Index"); } }
public ActionResult AssignUser(string id = "", string jobindexguid = "") { Logger.Debug("Inside Job Controller- Index"); try { if (Session["OrganizationGUID"] != null) { if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(jobindexguid)) { Job _job = new Job(); _job.JobGUID = new Guid(jobindexguid); _job.AssignedUserGUID = new Guid(id); _job.LastModifiedDate = DateTime.UtcNow; _job.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); int result = _IJobRepository.AssignJob(_job); if (result > 0) { Job job = _IJobRepository.GetJobByID(_job.JobGUID); if (job != null) { JobAssigned _jobAssigned = new JobAssigned(); _jobAssigned.JobAssignGUID = Guid.NewGuid(); _jobAssigned.JobGUID = job.JobGUID; _jobAssigned.UserGUID = job.AssignedUserGUID; _jobAssigned.StartTime = job.ScheduledEndTime; _jobAssigned.EndTime = job.ScheduledEndTime; _jobAssigned.Latitude = job.Latitude; _jobAssigned.Longitude = job.Longitude; _jobAssigned.LastModifiedDate = DateTime.UtcNow; _jobAssigned.LastModifiedBy = new Guid(Session["UserGUID"].ToString()); _IJobRepository.InsertJobAssigned(_jobAssigned); //_IJobRepository.Save(); } } // _IJobRepository.AssignUser(new Guid(id), new Guid(jobindexguid)); } return RedirectToAction("Index", "JobStatus"); } else { return RedirectToAction("SessionTimeOut", "User"); } } catch (Exception ex) { Logger.Error(ex.Message); return RedirectToAction("../User/Login"); } }