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)); } }