public async Task UploadImage(IFormFile file, GalleryMapperObject galleryMapperObject) { var fileUniqueName = ReturnUniqueFileName() + getFileExtension(file); var filePath = ReturnFullFilePath(this.webHostEnvironment.WebRootPath, fileUniqueName); await this.UploadImageInDB(file, fileUniqueName, galleryMapperObject); await this.UploadImageInFileStorage(file, filePath); }
public async Task <IEnumerable <Gallery> > ReturnFilesForDeletion(GalleryMapperObject galleryMapperObject) { var files = await this.personalBlogDbContext .Gallery .Where(g => g.ProjectId == galleryMapperObject.ProjectId && g.ArticleId == galleryMapperObject.ArticleId) .ToListAsync(); return(files); }
public async Task <bool> ObtainMultipleFiles(IEnumerable <IFormFile> files, GalleryMapperObject galleryMapperObject) { if (!this.ValidateMultupleFiles(files)) { return(false); } foreach (var file in files) { await this.UploadImage(file, galleryMapperObject); } return(true); }
public async Task <int> Create([FromForm] ArticleRequestModel articleRequestModel) { var userId = this.User.GetId(); var articleId = await this.articleService.CreateArticle(articleRequestModel, userId); var galleryObjectMapper = new GalleryMapperObject { ArticleId = articleId }; await this.galleryService.ObtainMultipleFiles(articleRequestModel.Gallery, galleryObjectMapper); return(articleId); }
public async Task UploadImageInDB(IFormFile file, string uniqueFilePath, GalleryMapperObject galleryMapperObject) { var uploadedFile = new Gallery() { ProjectId = galleryMapperObject.ProjectId, ArticleId = galleryMapperObject.ArticleId, FileName = uniqueFilePath }; this.personalBlogDbContext .Gallery .Add(uploadedFile); await this.personalBlogDbContext.SaveChangesAsync(); }
public async Task <ActionResult <int> > Create([FromForm] ProjectRequestModel projectModel) { var userId = this.User.GetId(); var projectId = await this.projectService.CreateProject(projectModel, userId); await this.projectTecnologyService.AddProjectTechnologyMapping(projectId, projectModel.Technologies); if (projectModel.Gallery.Count() > 0) { var galleryMaperObject = new GalleryMapperObject { ProjectId = projectId }; await this.galleryService.ObtainMultipleFiles(projectModel.Gallery, galleryMaperObject); } return(Created(nameof(Create), projectId)); }
public async Task <IActionResult> Delete(int id) { var userId = this.User.GetId(); var galleryMapperObject = new GalleryMapperObject { ProjectId = id }; var files = await this.galleryService.ReturnFilesForDeletion(galleryMapperObject); var isDeletionSuccessful = await this.projectService.DeleteProject(id, userId); if (!isDeletionSuccessful) { return(BadRequest()); } // await this.galleryService.DeleteImageFromDB(files); this.galleryService.DeleteImageFromFileStorage(files); return(Ok()); }