예제 #1
0
        public async Task <AnnoucementForViewDto> UpdateAnnoucement(AnnoucementForUpdateDto annoucementDto, int userId)
        {
            Annoucement annoucement = _mapper.Map <Annoucement>(annoucementDto);

            annoucement.UserId = userId;

            await _repo.Update(annoucement);

            await _repo.Save();

            if (annoucementDto.Photo != null)
            {
                string annoucementImageFolder = GetFolderNameForAnnoucementPhotos(annoucement.AnnoucementId);
                ImageFileProcessor.DeleteFolderWithAnnoucementPhotos(annoucementImageFolder);
                //var annoucementWithPhotos = await _repo.GetAll().Include(p => p.Photos).Where(x => x.AnnoucementId == annoucement.AnnoucementId).FirstOrDefaultAsync();
                //annoucementWithPhotos.Photos = new List<Photo>();
                List <string> generatedImageNames = UploadImages(annoucementDto.Photo, annoucementImageFolder);
                AddPhotosToAnnoucement(annoucement, generatedImageNames);
                await _repo.Save();
            }

            return(_mapper.Map <AnnoucementForViewDto>(annoucement));
        }
예제 #2
0
        private void DeleteFolderWithAnnoucementPhotos(int annoucementId)
        {
            string annoucementIdImageFolder = GetFolderNameForAnnoucementPhotos(annoucementId);

            ImageFileProcessor.DeleteFolderWithAnnoucementPhotos(annoucementIdImageFolder);
        }