public void TestDeleteObject()
        {
            var album = _albumRepository.FindOne(165);

            _albumRepository.Delete(album);
            Assert.IsNull(_albumRepository.FindOne(album.AlbumId));
        }
Exemple #2
0
        /// <summary>
        /// Delete an album
        /// </summary>
        /// <param name="albumid">Identity for the Album</param>
        /// <param name="deleterelated">If delete all related images or keep them</param>
        public void DeleteAlbum(int albumid, bool deleterelated)
        {
            Album album = AlbumRepository.GetByID(albumid);

            foreach (Image im in album.Images.ToList())
            {
                if (deleterelated == true)
                {
                    bool imagedeleted = DeleteImageFromStorage(im.Path, im.ThumbnailPath);
                    if (imagedeleted)
                    {
                        ImageRepository.Delete(im.ImageId);
                    }
                }
                else
                {
                    im.AlbumId = null;
                }
            }
            CloudBlobContainer cloudblobcontainer = GetContainerForAlbum(albumid);

            cloudblobcontainer.Delete();
            ImageRepository.UnitOfWork.Commit();
            AlbumRepository.Delete(albumid);
            AlbumRepository.UnitOfWork.Commit();
        }
Exemple #3
0
        public void DeleteAlbum(int albumId, bool deleteFiles)
        {
            var album = _albumRepository.Get(albumId);

            _albumRepository.Delete(albumId);
            _eventAggregator.PublishEvent(new AlbumDeletedEvent(album, deleteFiles));
        }
Exemple #4
0
        public bool Delete(int id)
        {
            var album = _repository.FindById(id);

            _repository.Delete(album);
            return(_repository.SaveChanges());
        }
Exemple #5
0
        /// <summary>
        /// 删除相册
        /// </summary>
        /// <remarks>
        /// 1.删除相册时同时删除相册下的所有照片以及照片的圈人;
        /// 2.注意需要删除动态,通过EventModule处理;
        /// 3.注意需要扣除新建相册时增加的积分,通过EventModule处理;
        /// 4.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更
        /// </remarks>
        /// <param name="album">相册对象</param>
        public void DeleteAlbum(Album album)
        {
            //删除相册下相片
            int pageCount = 1;
            int pageIndex = 1;

            do
            {
                PagingDataSet <Photo> photos = this.GetPhotosOfAlbum(null, album.AlbumId, true, SortBy_Photo.DateCreated_Desc, null, 100, pageIndex);
                foreach (Photo photo in photos)
                {
                    this.DeletePhoto(photo);
                }
                pageCount = photos.PageCount;
                pageIndex++;
            } while (pageIndex <= pageCount);

            //删除相册的推荐
            RecommendService recommendService = new RecommendService();

            recommendService.Delete(album.AlbumId, TenantTypeIds.Instance().Album());

            EventBus <Album> .Instance().OnBefore(album, new CommonEventArgs(EventOperationType.Instance().Delete()));

            albumRepository.Delete(album);

            EventBus <Album> .Instance().OnAfter(album, new CommonEventArgs(EventOperationType.Instance().Delete()));

            EventBus <Album, AuditEventArgs> .Instance().OnAfter(album, new AuditEventArgs(album.AuditStatus, null));
        }
Exemple #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            albumRepository.Delete(id);
            albumRepository.Save();

            return(RedirectToAction("Index"));
        }
Exemple #7
0
 private void btnEnleverAlbum_Click(object sender, EventArgs e)
 {
     if (libActive() == libCatalogue && libActive().SelectedItem is Album)
     {
         Album albumSelected = (Album)libActive().SelectedItem;
         _albumRepository.Delete(albumSelected);
         utilisateurConnecte.ListeAlbumPossede.Remove(albumSelected);
         utilisateurConnecte.ListeSouhait.Remove(albumSelected);
         try
         {
             if (albumSelected.Cover != "")
             {
                 File.Delete("..\\..\\..\\img\\" + albumSelected.Cover);
             }
         }
         catch (UnauthorizedAccessException)
         {
             MessageBox.Show("Accès refusé au dossier image, l'image de couverture n'a pas pu être supprimée", "Accès interdit", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         AffichageListes();
     }
     else if (libActive() != libCatalogue)
     {
         MessageBox.Show("La suppression d'albums du catalogue est disponible uniquement sur l'onglet 'Catalogue'", "Onglet incorrect", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else if (libActive().SelectedItem is Album == false)
     {
         MessageBox.Show("Veuillez sélectionner un album", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        public IActionResult Delete(int id)
        {
            var album = _albumRepository.GetById(id);

            _albumRepository.Delete(album);

            return(RedirectToAction("List"));
        }
Exemple #9
0
        public ActionResult DeleteAlbum(int id)
        {
            albumRepository.Delete(id);

            string message = "Album Deleted Succesfuly";

            return(RedirectToAction("Albums", new { message = message }));
        }
Exemple #10
0
        public void DeleteAlbum(int albumId, bool deleteFiles, bool addImportListExclusion = false)
        {
            var album = _albumRepository.Get(albumId);

            album.Artist.LazyLoad();
            _albumRepository.Delete(albumId);
            _eventAggregator.PublishEvent(new AlbumDeletedEvent(album, deleteFiles, addImportListExclusion));
        }
        public void DeleteAlbum(int albumId)
        {
            ExecuteFaultHandledOperation(() =>
            {
                IAlbumRepository albumRepository = _genericRepositoryFactory.GetGenericRepository <IAlbumRepository>();

                albumRepository.Delete(albumId);
            });
        }
 public HttpResponseMessage DeleteAlbum(int id)
 {
     if (albumRepository.IsUserHaveAccessToManage(User.Identity.GetUserId(), id))
     {
         Album album = albumRepository.GetById(id);
         albumRepository.Delete(album);
         return(new HttpResponseMessage(HttpStatusCode.OK));
     }
     throw new HttpResponseException(HttpStatusCode.InternalServerError);
 }
Exemple #13
0
        public void Delete(long tenantId, long elementId, IUnitOfWork unitOfWork = null)
        {
            // If we don't have a unit of work in place, create one now so that we can rollback all changes in case of failure
            IUnitOfWork localUnitOfWork = unitOfWork == null?_unitOfWorkFactory.CreateUnitOfWork() : null;

            // Begin work
            try
            {
                // Get album settings
                AlbumSettings albumSettings = (AlbumSettings)New(tenantId);
                albumSettings.ElementId = elementId;
                _albumRepository.Read(albumSettings, unitOfWork ?? localUnitOfWork);

                // Delete album from underlying storage
                _albumRepository.Delete(tenantId, elementId, unitOfWork ?? localUnitOfWork);

                // Delete photo images
                foreach (AlbumPhoto photo in albumSettings.Photos)
                {
                    _uploadService.Delete(photo.ImageTenantId, photo.ThumbnailImageUploadId, GetAlbumPhotoStorageHierarchy(photo.ElementId), unitOfWork ?? localUnitOfWork);
                    _uploadService.Delete(photo.ImageTenantId, photo.PreviewImageUploadId, GetAlbumPhotoStorageHierarchy(photo.ElementId), unitOfWork ?? localUnitOfWork);
                    _uploadService.Delete(photo.ImageTenantId, photo.ImageUploadId, GetAlbumPhotoStorageHierarchy(photo.ElementId), unitOfWork ?? localUnitOfWork);
                }

                // Commit work if local unit of work in place and return result
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Commit();
                }
            }
            catch (ValidationErrorException)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw;
            }
            catch (Exception ex)
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Rollback();
                }
                throw new ValidationErrorException(new ValidationError(null, ApplicationResource.UnexpectedErrorMessage), ex);
            }
            finally
            {
                if (localUnitOfWork != null)
                {
                    localUnitOfWork.Dispose();
                }
            }
        }
        public void DeleteAlbum(Guid id)
        {
            Expect.ArgumentNotNull(id);
            IAlbumRepository repository = AlbumRepository;
            Album            album      = GetAlbumById(id);

            PhotoRepository.DeleteAll(album.Photos);
            if (GetAlbumById(id) != null)
            {
                repository.Delete(id);
            }
        }
Exemple #15
0
        public async Task <IActionResult> Delete(long id)
        {
            var post = await _repo.GetTodo(id);

            if (post == null)
            {
                return(new NotFoundResult());
            }
            await _repo.Delete(id);

            return(new OkResult());
        }
Exemple #16
0
        public async Task <IActionResult> DeleteAlbum(int albumId, [FromQuery] bool removeFiles = false)
        {
            var album = await _albumRepo.GetAlbumById(albumId);

            if (album == null)
            {
                return(NotFound("Album with that Id was not found"));
            }

            int userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (album.OwnerId != userId)
            {
                return(Unauthorized("You dont own this album"));
            }

            if (album.UFiles.Count != 0)
            {
                // remove files if flag is set
                foreach (var file in album.UFiles)
                {
                    if (removeFiles)
                    {
                        _fileRepo.Delete(file);
                        string path = _utilsService.GenerateFilePath(file.PublicId, file.FileExtension);
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                    else
                    {
                        file.AlbumId = null;
                    }
                }

                if (!await _fileRepo.SaveAll())
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError,
                                      new { message = "Failed saving to database" }));
                }
            }

            _albumRepo.Delete(album);

            if (!await _albumRepo.SaveAll())
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = "Failed saving to database" }));
            }

            return(Ok());
        }
        public async Task <ServiceResult> Delete(string id)
        {
            var serviceResult = new ServiceResult();
            var result        = await _albumRepository.Delete(id);

            serviceResult.Success = result.Success;
            if (!result.Success)
            {
                serviceResult.Error.Code        = ErrorStatusCode.BudRequest;
                serviceResult.Error.Description = result.Message;
            }
            return(serviceResult);
        }
Exemple #18
0
 public ActionResult Delete(Album a)
 {
     try
     {
         // TODO: Add delete logic here
         _albumRepository.Delete(a.AlbumId);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Exemple #19
0
        public ActionResult Delete(string owner, string name)
        {
            var deleted = repository.Delete(owner, name);

            if (deleted == null)
            {
                return(NotFound());
            }
            else
            {
                return(NoContent());
            }
        }
Exemple #20
0
        public async Task <IActionResult> DeleteConfirmed([FromRoute] int?id, [FromServices] IAlbumRepository albumRepository, CancellationToken cancellationToken = default)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            Album album = await albumRepository.FindAlbum(id.Value, cancellationToken : cancellationToken);

            cancellationToken.ThrowIfCancellationRequested();

            await albumRepository.Delete(album);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> DeleteAlbum([FromRoute] Guid artistId, [FromRoute] Guid albumId)
        {
            var albumFromRepo = await _albumRepository.GetAlbumForArtistAsync(albumId, artistId);

            if (albumFromRepo == null)
            {
                return(NotFound());
            }

            _albumRepository.Delete(albumFromRepo);

            if (!await _albumRepository.SaveChangesAsync())
            {
                throw new Exception($"deleting for album {albumId} failed");
            }

            return(Ok());
        }
        public async Task <IActionResult> AdminDeleteUser(int userId)
        {
            int reqUserId = this.GetRequestUserId();

            if (await _userRepo.IsAdmin(reqUserId) == false)
            {
                return(Unauthorized());
            }
            // get user
            var user = await _userRepo.GetUserById(userId);

            if (user == null)
            {
                return(NotFound());
            }

            // Remove all files
            foreach (var file in user.Files)
            {
                string path = _utilsService.GenerateFilePath(file.PublicId, file.FileExtension);
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                _fileRepo.Delete(file);
            }
            await _fileRepo.SaveAll();

            // Remove albums
            foreach (var album in user.Albums)
            {
                _albumRepo.Delete(album);
            }
            await _albumRepo.SaveAll();

            // Remove ApiKey
            await _apiKeyRepo.RemoveApiKeyByUserId(user.Id);

            // remove user
            await _userRepo.RemoveUser(user);

            return(Ok());
        }
Exemple #23
0
        /// <summary>
        /// Delete an album
        /// </summary>
        /// <param name="albumid">Identity for the Album</param>
        /// <param name="deleterelated">If delete all related images or keep them</param>
        /// <param name="server">Server base</param>
        public void DeleteAlbum(int albumid, bool deleterelated, HttpServerUtilityBase server)
        {
            Album album = AlbumRepository.GetByID(albumid);

            foreach (Image im in album.Images.ToList())
            {
                if (deleterelated == true)
                {
                    DeleteImageFromServer(server.MapPath(im.Path), server.MapPath(im.ThumbnailPath));
                    ImageRepository.Delete(im.ImageId);
                }
                else
                {
                    im.AlbumId = null;
                }
            }
            ImageRepository.UnitOfWork.Commit();
            AlbumRepository.Delete(albumid);
            AlbumRepository.UnitOfWork.Commit();
        }
 public DataModel.Response.BaseResponse DeleteAlbum(string id)
 {
     try
     {
         IAlbumRepository albumRepository = RepositoryClassFactory.GetInstance().GetAlbumRepository();
         albumRepository.Delete(id);
         return(new BaseResponse
         {
             ErrorCode = (int)ErrorCode.None,
             Message = Resources.Resource.msg_delete_success
         });
     }
     catch (Exception ex)
     {
         return(new BaseResponse
         {
             ErrorCode = (int)ErrorCode.Error,
             Message = ex.Message
         });
     }
 }
Exemple #25
0
        private void btnSupressionSure_Click(object sender, EventArgs e)
        {
            gbSuppression.Visible = false;
            Album AlbumASuprimmer = _albumrepo.GetAlbumByTitle(tbSupression.Text);

            if (AlbumASuprimmer.Nom == null)
            {
                MessageBox.Show("Le titre que vous avez entré ne correspond a aucun album du marché. Veuillez réassayer.");
            }
            else
            {
                Domain.Action ActionASupprimer = _actionrepo.GetActionByNameAndAlbum(AlbumASuprimmer, "AjoutMarché");
                if (ActionASupprimer.Nom != null)
                {
                    _actionrepo.DeleteAction(ActionASupprimer);
                    _albumrepo.Delete(AlbumASuprimmer);
                    MessageBox.Show("L'album " + AlbumASuprimmer.Nom + " a bien été supprimé du marché ! ");
                }
                RefreshDgv();
            }
        }
        public ICommandResult Handle(DeleteAlbumCommand command)
        {
            if (command.Id.ToString().Length == 0)
            {
                AddNotification("Id", string.Format(MessagesUtil.InvalidField, "Identificador"));
            }

            if (Invalid)
            {
                return(new CommandResult(false, string.Format(MessagesUtil.InvalidField, "Identificador"), Notifications));
            }

            bool result = _repository.Delete(command.Id);

            if (!result)
            {
                return(new CommandResult(false, MessagesUtil.DeleteError, Notifications));
            }

            return(new CommandResult(true, MessagesUtil.DeletedSuccess));
        }
Exemple #27
0
        public async Task <ActionResultResponse> Delete(string tenantId, string albumId)
        {
            var info = await _albumRepository.GetInfo(albumId);

            if (info == null)
            {
                return(new ActionResultResponse(-1, _websiteResourceService.GetString("Album does not exists. Please try again.")));
            }

            if (info.TenantId != tenantId)
            {
                return(new ActionResultResponse(-2, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            var result = await _albumRepository.Delete(albumId);

            if (result <= 0)
            {
                return(new ActionResultResponse(-3, _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            if (info.Type == AlbumType.Photo)
            {
                await _albumTranslationRepository.Delete(albumId);
            }

            if (info.Type == AlbumType.Video)
            {
                var listVideo = await _videoRepository.GetsByAlbumId(albumId);

                if (listVideo != null && listVideo.Any())
                {
                    await _videoRepository.DeleteListVideo(listVideo);
                }
            }
            await _photoRepository.DeleteByAlbumId(albumId);

            return(new ActionResultResponse(result, _websiteResourceService.GetString("Delete album successful.")));
        }
        public void DeleteById(int id)
        {
            var album = AlbumRepository.GetById(id);

            ArtistRepository.DeleteIfNoAlbums(album.ArtistId);

            var tempPictures = album.Pictures.Select(x => new { Id = x.PictureId, Path = x.Path, FileName = x.FileName }).ToList();

            foreach (var pic in tempPictures)
            {
                PictureService.Delete(pic.Path, pic.FileName);
                PictureRepository.Delete(pic.Id);
            }

            var tempPurchases = album.Purchases.ToList();

            foreach (var purchase in tempPurchases)
            {
                PurchaseRepository.Delete(purchase.AlbumId, purchase.ProfileId);
            }

            AlbumRepository.Delete(album.AlbumId);
        }
Exemple #29
0
        public ActionResult Delete(int?id, Album album)
        {
            if (!id.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            if (!ModelState.IsValid)
            {
                return(View(album));
            }

            var dbArtist = _albumRepository.GetById(id.Value);

            if (dbArtist == null)
            {
                return(RedirectToAction("Index"));
            }

            _albumRepository.Delete(dbArtist);
            _albumRepository.Update(album);

            return(RedirectToAction("Index"));
        }
 public void DeleteAlbum(AlbumEntity album)
 {
     albumRepository.Delete(album.ToDal());
     uow.Commit();
 }