/// <summary> /// Returns a list of map plotting objects based on filters /// </summary> /// <param name="parameters">Object that contains all the parameters for the request</param> /// <returns>List of map plotting objects</returns> public IList<Globals.MapPlotDataObject> FilterMapPlotting(Globals.MapPlotRequestDataObject parameters) { int activeJobStatus = (int)Globals.JobRecord.JobStatus.Active; int generalLogJobId = Globals.GeneralLog.ID; bool hasDivisions = parameters.DivisionList != null; bool hasJobAction = parameters.JobActionList != null; bool hasJobCategory = parameters.JobCategoryList != null; bool hasPriceType = parameters.PriceTypeList != null; if (parameters.DivisionList == null) parameters.DivisionList = new int[0]; if (parameters.JobActionList == null) parameters.JobActionList = new int[0]; if (parameters.JobCategoryList == null) parameters.JobCategoryList = new int[0]; if (parameters.PriceTypeList == null) parameters.PriceTypeList = new int[0]; DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MaxValue; if (parameters.CreationDate.HasValue) { startDate = parameters.CreationDate.Value.Date; endDate = parameters.CreationDate.Value.Date.AddDays(1).AddSeconds(-1); } IList<CS_Job> jobList = _jobRepository.ListAll( e => (!parameters.JobNumberID.HasValue || e.ID == parameters.JobNumberID.Value) && (!parameters.CustomerID.HasValue || e.CS_CustomerInfo.CustomerId == parameters.CustomerID.Value) && (!parameters.StateID.HasValue || e.CS_LocationInfo.StateID == parameters.StateID.Value) && (hasDivisions ? e.CS_JobDivision.Any(f => parameters.DivisionList.Contains(f.DivisionID) && f.Active) : true) && (hasJobAction ? parameters.JobActionList.Any(f => e.CS_JobInfo.JobActionID == f) : true) && (hasJobCategory ? parameters.JobCategoryList.Contains(e.CS_JobInfo.JobCategoryID) : true) && (hasPriceType ? parameters.PriceTypeList.Contains(e.CS_JobInfo.PriceTypeID) : true) && (!parameters.CreationDate.HasValue || (e.CreationDate >= startDate && e.CreationDate <= endDate)) && e.ID != generalLogJobId && e.CS_JobInfo.CS_Job_JobStatus.Any(f => f.Active && f.JobStatusId == activeJobStatus) , "CS_JobInfo", "CS_JobInfo.CS_Job_JobStatus", "CS_JobInfo.CS_PriceType", "CS_JobInfo.CS_JobType", "CS_CustomerInfo", "CS_CustomerInfo.CS_Customer", "CS_LocationInfo", "CS_LocationInfo.CS_Country", "CS_LocationInfo.CS_State", "CS_LocationInfo.CS_City", "CS_LocationInfo.CS_Zipcode"); IList<Globals.MapPlotDataObject> returnList = new List<Globals.MapPlotDataObject>(); for (int i = 0; i < jobList.Count; i++) { CS_Job currentJob = jobList[i]; Globals.MapPlotDataObject mapObject = new Globals.MapPlotDataObject(); if (currentJob.CS_LocationInfo.CS_ZipCode.Latitude.HasValue) mapObject.Latitude = currentJob.CS_LocationInfo.CS_ZipCode.Latitude.Value; if (currentJob.CS_LocationInfo.CS_ZipCode.Longitude.HasValue) mapObject.Longitude = currentJob.CS_LocationInfo.CS_ZipCode.Longitude.Value; mapObject.Type = "J"; mapObject.Name = string.Format("Job #: {0}", currentJob.PrefixedNumber); mapObject.Description = string.Format("Company: {0}<br/>", currentJob.CS_CustomerInfo.CS_Customer.Name); mapObject.Description += string.Format("Location: {0}, {1}, {2}, {3}", currentJob.CS_LocationInfo.CS_City.Name, currentJob.CS_LocationInfo.CS_State.Acronym, currentJob.CS_LocationInfo.CS_Country.Name, currentJob.CS_LocationInfo.CS_ZipCode.ZipCodeNameEdited); returnList.Add(mapObject); } // Fix position for jobs at the same point for (int i = 0; i < returnList.Count; i++) { IList<Globals.MapPlotDataObject> samePointList = returnList.Where(e => e.Latitude == returnList[i].Latitude && e.Longitude == returnList[i].Longitude).ToList(); double newLongitude = returnList[i].Longitude; double newLatitude = returnList[i].Latitude; for (int j = 0; j < samePointList.Count; j++) { newLongitude += 0.005; newLatitude += 0.005; samePointList[j].Longitude = newLongitude; samePointList[j].Latitude = newLatitude; } } return returnList; }
public Globals.MapPlotDataObject[] GetMapPlottingObjects(Globals.MapPlotRequestDataObject mapPlotFilter) { _presenter = new JSONServicePresenter(this); MapPlottingFilter = mapPlotFilter; _presenter.GetMapPlottingObjects(); if (null != MapPlottingObjectsList) { Globals.MapPlotDataObject[] returnList = new Globals.MapPlotDataObject[MapPlottingObjectsList.Count]; for (int i = 0; i < MapPlottingObjectsList.Count; i++) { returnList[i] = new Globals.MapPlotDataObject() { Latitude = MapPlottingObjectsList[i].Latitude, Longitude = MapPlottingObjectsList[i].Longitude, Type = MapPlottingObjectsList[i].Type, Description = MapPlottingObjectsList[i].Description, Name = MapPlottingObjectsList[i].Name }; } return returnList; } else return null; }
/// <summary> /// Returns a list of map plotting objects based on filters /// </summary> /// <param name="parameters">Object that contains all the parameters for the request</param> /// <returns>List of map plotting objects</returns> public IList<Globals.MapPlotDataObject> FilterMapPlotting(Globals.MapPlotRequestDataObject parameters) { bool hasEquipmentType = parameters.EquipmentTypeList != null; bool hasRegionList = parameters.RegionList != null; if (null == parameters.EquipmentTypeList) parameters.EquipmentTypeList = new int[0]; if (null == parameters.RegionList) parameters.RegionList = new int[0]; int activeJobStatus = (int)Globals.JobRecord.JobStatus.Active; int generalLogJobId = Globals.GeneralLog.ID; IList<CS_Resource> resourceList = _resourceRepository.ListAll( e => (hasEquipmentType ? (e.EquipmentID.HasValue && parameters.EquipmentTypeList.Contains(e.CS_Equipment.EquipmentTypeID)) : true) && (hasRegionList ? (e.EquipmentID.HasValue && e.CS_Equipment.CS_Division.CS_Region_Division.Any(f => f.Active && parameters.RegionList.Contains(f.RegionID))) : true) && (string.IsNullOrEmpty(parameters.ComboNumber) || (e.EquipmentID.HasValue && e.CS_Equipment.ComboID.HasValue && e.CS_Equipment.CS_EquipmentCombo.Name.Contains(parameters.ComboNumber))) && (string.IsNullOrEmpty(parameters.UnitNumber) || (e.EquipmentID.HasValue && e.CS_Equipment.Name.Contains(parameters.UnitNumber))) && (string.IsNullOrEmpty(parameters.EmployeeName) || (e.EmployeeID.HasValue && (e.CS_Employee.Name.Contains(parameters.EmployeeName) || e.CS_Employee.FirstName.Contains(parameters.EmployeeName)))) && (string.IsNullOrEmpty(parameters.EmployeeTitle) || (e.EmployeeID.HasValue && e.CS_Employee.BusinessCardTitle.Contains(parameters.EmployeeTitle))) && e.Active && ((!parameters.JobNumberID.HasValue) || (parameters.JobNumberID.HasValue && e.CS_Job.ID == parameters.JobNumberID.Value)) && e.CS_Job.ID != generalLogJobId && e.CS_Job.CS_JobInfo.CS_Job_JobStatus.Any(f => f.Active && f.JobStatusId == activeJobStatus), "CS_Job", "CS_Job.CS_JobInfo", "CS_Job.CS_JobInfo.CS_Job_JobStatus", "CS_Job.CS_JobInfo.CS_PriceType", "CS_Job.CS_JobInfo.CS_JobType", "CS_Job.CS_LocationInfo", "CS_Job.CS_LocationInfo.CS_Country", "CS_Job.CS_LocationInfo.CS_State", "CS_Job.CS_LocationInfo.CS_City", "CS_Job.CS_LocationInfo.CS_ZipCode", "CS_Equipment", "CS_Equipment.CS_EquipmentCombo", "CS_Employee"); IList<Globals.MapPlotDataObject> returnList = new List<Globals.MapPlotDataObject>(); for (int i = 0; i < resourceList.Count; i++) { CS_Resource currentResource = resourceList[i]; Globals.MapPlotDataObject mapObject = new Globals.MapPlotDataObject(); if (currentResource.CS_Job.CS_LocationInfo.CS_ZipCode.Latitude.HasValue) mapObject.Latitude = currentResource.CS_Job.CS_LocationInfo.CS_ZipCode.Latitude.Value; if (currentResource.CS_Job.CS_LocationInfo.CS_ZipCode.Longitude.HasValue) mapObject.Longitude = currentResource.CS_Job.CS_LocationInfo.CS_ZipCode.Longitude.Value; mapObject.Type = "R"; mapObject.Name = string.Format("Job #: {0}", currentResource.CS_Job.PrefixedNumber); mapObject.Description = string.Format("Location: {0}, {1}, {2}, {3}", currentResource.CS_Job.CS_LocationInfo.CS_City.Name, currentResource.CS_Job.CS_LocationInfo.CS_State.Acronym, currentResource.CS_Job.CS_LocationInfo.CS_Country.Name, currentResource.CS_Job.CS_LocationInfo.CS_ZipCode.ZipCodeNameEdited); if (currentResource.EquipmentID.HasValue) { if (currentResource.CS_Equipment.ComboID.HasValue) mapObject.Description += string.Format("<br />Resource: {0} - {1}", currentResource.CS_Equipment.CS_EquipmentCombo.Name, currentResource.CS_Equipment.Description); else mapObject.Description += string.Format("<br />Resource: {0} - {1}", currentResource.CS_Equipment.Name, currentResource.CS_Equipment.Description); } else mapObject.Description += string.Format("<br />Resource: {0}", currentResource.CS_Employee.FullName); returnList.Add(mapObject); } // Fix position for jobs at the same point for (int i = 0; i < returnList.Count; i++) { IList<Globals.MapPlotDataObject> samePointList = returnList.Where(e => e.Latitude == returnList[i].Latitude && e.Longitude == returnList[i].Longitude).ToList(); double newLongitude = returnList[i].Longitude; double newLatitude = returnList[i].Latitude; for (int j = 0; j < samePointList.Count; j++) { newLongitude += 0.005; newLatitude += 0.005; samePointList[j].Longitude = newLongitude; samePointList[j].Latitude = newLatitude; } } return returnList; }