- Back to Home »
- C# , Umbraco , Web Service »
Posted by : Jebastin
Saturday, 14 December 2013
Web Service to filter the Umbraco Nodes
The following WebMethod is used to filter the Umbraco child nodes of a particular parent node using the given parent id by the parameters Keyword, Job Type, Position, Location, Category and Division.Web Method:
- public List<JobDetails> FilterJobs(int ParentId, string Keyword, string JobType, string Position, string Location, string Category, string Division)
- {
- string strJobId = "", strJobDescription = "", strJobRequirements = "", strJobType = "";
- string strJobPosition = "", strJobLocation = "", strJobCategory = "", strJobDivision = "";
- dynamic JobsNode = new DynamicNode().NodeById(ParentId);
- List<DynamicNode> JobsList = JobsNode.Children.Items;
- List<JobDetails> FilteredJobsList = new List<JobDetails>();
- JobsList = JobsList.Where(x => x.GetProperty("descriptionOfDuties").Value.Contains(Keyword) ||
- x.GetProperty("requirementsExperience").Value.Contains(Keyword) ||
- x.GetProperty("jobType").Value.Contains(Keyword) ||
- x.GetProperty("position").Value.Contains(Keyword) ||
- x.GetProperty("location").Value.Contains(Keyword) ||
- x.GetProperty("category").Value.Contains(Keyword) ||
- x.GetProperty("division").Value.Contains(Keyword) ||
- Keyword == "").ToList();
- JobsList = JobsList.Where(x => (x.GetProperty("jobType").Value.Equals(JobType) || JobType == "") &&
- (x.GetProperty("position").Value.Equals(Position) || Position == "") &&
- (Location.Split(',').Contains(x.GetProperty("location").Value.Replace(",", "")) || Location == "") &&
- (Category.Split(',').Contains(x.GetProperty("category").Value) || Category == "") &&
- (Division.Split(',').Contains(x.GetProperty("division").Value) || Division == "")).ToList();
- foreach (var job in JobsList)
- {
- strJobId = Convert.ToString(job.Id);
- strJobDescription = job.GetProperty("descriptionOfDuties").Value;
- strJobRequirements = job.GetProperty("requirementsExperience").Value;
- strJobType = job.GetProperty("jobType").Value;
- strJobPosition = job.GetProperty("position").Value;
- strJobLocation = job.GetProperty("location").Value;
- strJobCategory = job.GetProperty("category").Value;
- strJobDivision = job.GetProperty("division").Value;
- FilteredJobsList.Add(new JobDetails
- {
- JobId = strJobId.Trim(),
- JobDescription = strJobDescription.Trim(),
- JobRequirements = strJobRequirements.Trim(),
- JobType = strJobType.Trim(),
- JobPosition = strJobPosition.Trim(),
- JobLocation = strJobLocation.Trim(),
- JobCategory = strJobCategory.Trim(),
- JobDivision = strJobDivision.Trim()
- });
- }
- return FilteredJobsList;
- }
Properties:
- public class JobDetails
- {
- public string JobId { get; set; }
- public string JobDescription { get; set; }
- public string JobRequirements { get; set; }
- public string JobType { get; set; }
- public string JobPosition { get; set; }
- public string JobLocation { get; set; }
- public string JobCategory { get; set; }
- public string JobDivision { get; set; }
- }