public IActionResult Index() { var model = new MyGifsViewModel(); try { // First we obtain all the Categories the user have in its profile var categories = _categoryService.GetCategoriesByUser(GetUserEmail()); if (categories != null) { PictureViewModel viewPictures = null; foreach (var item in categories) { // Get the pics for every Category var dbPictures = _pictureService.GetAllGifsByUserAndCategory(GetUserEmail(), item.CategoryId); if (dbPictures != null) { viewPictures = new PictureViewModel(); foreach (var item2 in dbPictures) { viewPictures.Pictures.Add(ObjectTransformations.TransformDbtoViewObj(item2)); } } // Add the Category --> Pics into the Category to the model model.ListOfCategorizedPictures.Add( new CategoryPicturesViewModel(ObjectTransformations.TransformDbtoViewObj(item), viewPictures)); } } } catch (System.Exception) { ViewBag.IsError = true; ViewBag.Message = $"Unexpected error ocurred while Retrieving the Pictures for each Category for user: '******'. Try again later!"; return(View(model)); } return(View(model)); }