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()); }
/// <summary> /// Transform a picture database object to a Category view Obj /// </summary> /// <param name="picture"></param> /// <returns></returns> public static ViewObj.Picture TransformDbtoViewObj(DbObj.Picture picture) { ViewObj.Picture newPicture = null; if (picture != null) { newPicture = new ViewObj.Picture { PictureId = picture.PictureId, CategoryId = picture.CategoryId, Name = picture.Name, Description = picture.Description, FileName = picture.FileName, SourceUrl = picture.SourceUrl, Height = picture.Height, Width = picture.Width }; } return(newPicture); }
/// <summary> /// Transform a picture view object to a Category EF Obj /// </summary> /// <param name="picture"></param> /// <returns></returns> public static DbObj.Picture TransformViewToDbObj(ViewObj.Picture picture) { DbObj.Picture newPicture = null; if (picture != null) { newPicture = new DbObj.Picture { PictureId = picture.PictureId, CategoryId = picture.CategoryId, Name = picture.Name, Description = picture.Description, FileName = picture.FileName, SourceUrl = picture.SourceUrl, Height = picture.Height, Width = picture.Width, Image = null, // Field that needs to be setup from outside the transformation UserEmail = string.Empty // Field that needs to be setup from outside the transformation }; } return(newPicture); }