public async Task <IActionResult> Tehtudtood() { var tehtudTood = await _tehtudTood.GetAllTehtudTood(); IList <TehtudToodIndexListingModel> tehtudToodListing = new List <TehtudToodIndexListingModel>(); // List for the years when the jobs were done. IList <int> yearsDoneIn = new List <int>(); // Assing queried objects to a list foreach (var tehtudToo in tehtudTood) { // Check if we have the job done year already in the list, if not add it. if (!yearsDoneIn.Contains(tehtudToo.YearDone)) { yearsDoneIn.Add(tehtudToo.YearDone); } // Create and add a view model to the listing tehtudToodListing.Add(new TehtudToodIndexListingModel { Name = tehtudToo.Name, YearDone = tehtudToo.YearDone, BuildingType = tehtudToo.BuildingType, Images = tehtudToo.Images.Select(imgresult => new TehtudTooImages { ImageFileName = imgresult.ImageFileName }) }); } // Sort the years done in list to show highest first. var sortedYearsList = yearsDoneIn.OrderByDescending(i => i); var model = new TehtudToodIndexModel() { TehtudToodViewList = tehtudToodListing, TehtudToodYears = sortedYearsList }; return(View(model)); }
// GET: TehtudTood /// <summary> /// Get a list of Tehtud tööd and parse them to view model list to be displayed /// </summary> /// <returns></returns> public async Task <IActionResult> Index() { return(View(ParseMultipleEntityModelsToViewModels(await _tehtudTood.GetAllTehtudTood()))); }