public IActionResult Save(User user) { try { if (ModelState.IsValid) { if (!_userService.VerifyRegisteredUser(user.UserEmail)) // If user not registered { var userDb = ObjectTransformations.TransformViewToDbObj(user); // Send Email to the User & Admin Email.sendEmail(user.UserEmail, user.Name); _userService.AddUserRegistration(userDb); ViewBag.IsError = "false"; ViewBag.Message = "User registered sucessfully!"; return(View()); } else { ViewBag.IsError = true; ViewBag.Message = $"User already Registered: '{user.UserEmail}'. Try with a different email!"; } } return(View("Register")); } catch (System.Exception) { ViewBag.IsError = true; ViewBag.Message = $"Unexpected error ocurred while Registering user: '******'. Try again later!"; return(View("Register")); } }
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 AddEdit(ObjView.Category model) { try { if (ModelState.IsValid) { var catDb = ObjectTransformations.TransformViewToDbObj(model); catDb.UserEmail = GetUserEmail(); // Azure user information // Add/Update category in the db _categoryService.AddEditCategory(catDb); ViewBag.IsError = "false"; ViewBag.Message = "Category added/updated sucessfully!"; return(RedirectToAction("Index", "Picture")); } else { return(View()); } } catch (Exception) { ViewBag.IsError = true; ViewBag.Message = $"Unexpected error ocurred while Saving the Category for user: '******'. Try again later!"; return(RedirectToAction("Index", "Picture")); } }
public IActionResult Edit(ObjView.Picture picture) { try { if (picture != null && ModelState.IsValid) { var newDbPic = ObjectTransformations.TransformViewToDbObj(picture); // Save the img in the database _pictureService.UpdateGifAnimatedToDB(newDbPic); ViewBag.Message = "The Picture Has Been Saved Successfully in your Profile!"; return(View("Common")); } return(RedirectToAction(nameof(Index))); } catch (System.Exception) { ViewBag.Message = "Unexpected error when saving the Picture in the Database. Try again later!"; return(RedirectToAction(nameof(Index))); } }
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)); }