public ActionResult Index(string Position = null, string Searching = null) { //get the list of developers, send them to the main view List <Developer> developers = context.Collection().ToList(); List <DeveloperPosition> positions = developerPositions.Collection().ToList(); if (Position == null && (Searching == null | Searching == ""))//Show all { developers = context.Collection().ToList(); } else if (!(Position == null) && (Searching == null | Searching == "")) { developers = context.Collection().Where(p => p.Position == Position).ToList(); } else if (Position == null && !(Searching == null | Searching == "")) { developers = context.Collection().Where(p => p.FullName.Contains(Searching)).ToList(); } else//both must satisfy { developers = context.Collection().Where(p => p.FullName.Contains(Searching) && p.Position == Position).ToList(); } DeveloperListViewModel model = new DeveloperListViewModel(); model.Developers = developers; model.DeveloperPositions = positions; return(View(model));//return the list to the view }
public void Respond(List <DeveloperDto> response) { ContentResult = new DeveloperListViewModel() { Count = response.Count, Developers = response .Select(d => new DeveloperViewModel() { Id = d.DeveloperId, DisplayName = d.FirstName + " " + d.LastName, Gender = d.Gender, Level = d.Level, PrimaryLanguage = d.PrimaryLanguage, YearsOfExperience = d.YearsOfExperience }) .ToList() }; }