public IActionResult Save(ObjView.Picture picture) { try { if (picture != null) { var downloadedData = downloadFileFromUrl(picture.SourceUrl); if (downloadedData != null) { if (picture.CategoryId < 1) { // Add the "GENERAL category to every user only the first time (when there's no category available) picture.CategoryId = _categoryService.AddEditCategory(new ObjDb.Category { CategoryId = picture.CategoryId, Name = Constants.DEFAULT_PIC_CATEGORY, Description = Constants.DEFAULT_PIC_CATEGORY, UserEmail = GetUserEmail() }); } // Create the DB Picture object var newDbPic = new ObjDb.Picture { UserEmail = GetUserEmail(), CategoryId = picture.CategoryId, Name = picture.Name, Description = picture.Description, FileName = picture.FileName, SourceUrl = picture.SourceUrl, Height = picture.Height, Width = picture.Width, Image = downloadedData }; // Save the img in the database _pictureService.AddGifAnimatedToDB(newDbPic); ViewBag.Message = "The Picture Has Been Saved Successfully in your Profile!"; } } } catch (System.Exception) { ViewBag.Message = "Unexpected error when saving the Picture in the Database. Try again later!"; } return(View()); }