public IActionResult Index() { var plants = plantService.GetAllPlantsOfUser(User.Identity.Name); IEnumerable <MyPlantsPlantCardViewModel> plantCards = plants.Select(x => new MyPlantsPlantCardViewModel() { Id = x.Id, Name = x.Name, WateringPeriod = x.WateringPeriod }); MyPlantsViewModel mpvw = new MyPlantsViewModel() { plantCards = plantCards }; return(View(mpvw)); }
public IActionResult Search(string searchText) { if (searchText == null) { return(RedirectToAction("Index")); } var plants = plantService.GetPlantsByName(searchText, User.Identity.Name); IEnumerable <MyPlantsPlantCardViewModel> plantCards = plants.Select(x => new MyPlantsPlantCardViewModel() { Id = x.Id, Name = x.Name, WateringPeriod = x.WateringPeriod }); MyPlantsViewModel mpvw = new MyPlantsViewModel() { plantCards = plantCards }; return(View("Index", mpvw)); }