public IActionResult SavePicture(string sourceUrl, string fileName, int height, int width) { try { var picture = new ObjView.Picture { SourceUrl = sourceUrl, FileName = fileName, Height = height, Width = width }; // Get all the categories previously saved by the user var categories = _categoryService.GetCategoriesByUser(GetUserEmail()); var viewCategories = new List <ObjView.Category>(); if (categories != null) { // Convert DB object to View object foreach (var item in categories) { viewCategories.Add(ObjectTransformations.TransformDbtoViewObj(item)); } } var model = new PictureCategoryViewModel(picture, viewCategories); return(View(model)); } catch (System.Exception) { return(RedirectToAction("Index", "SearchGifsController")); } }
public IActionResult Edit(string id) { PictureCategoryViewModel model = new PictureCategoryViewModel(); try { int picId = Convert.ToInt32(id); if (picId > 0) { // Get the picture by Id and User Email coming from Azure model.Picture = ObjectTransformations.TransformDbtoViewObj(_pictureService.GetPictureByUserAndId(GetUserEmail(), picId)); } // Existing Categories saved previously by the User var categories = _categoryService.GetCategoriesByUser(GetUserEmail()); if (categories != null) { // Convert DB object to View object foreach (var item in categories) { model.UserCategories.Add(ObjectTransformations.TransformDbtoViewObj(item)); } } return(View(model)); } catch (Exception) { model.IsError = true; model.Message = $"Unexpected error ocurred while Retrieving Category for user: '******'. Try again later!"; return(View(model)); } }
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)); }