public async Task<bool> DeleteAlbum(int id)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
                throw new ApiException("You have to be logged in to modify data", 401);

            return await AlbumRepo.DeleteAlbum(id);
        }
        public async Task <string> DeleteAlbumByName(string name)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                throw new ApiException("You have to be logged in to modify data", 401);
            }

            var repo = new AlbumRepository(context);

            var pks = await context.Albums.Where(alb => alb.Title == name).Select(alb => alb.Id).ToAsyncEnumerable().ToList();

            StringBuilder sb = new StringBuilder();

            foreach (int pk in pks)
            {
                bool result = await repo.DeleteAlbum(pk);

                if (!result)
                {
                    sb.AppendLine(repo.ErrorMessage);
                }
            }

            return(sb.ToString());
        }
示例#3
0
        public ActionResult DeleteAlbum(Guid albumId)
        {
            var userRepo = new UserRepository();

            var user = new User(userRepo.GetUserById((Guid)Session["UserId"]));

            user.Albums = Dal.GetUserAlbum(user.UserId).Select(x => new Album(x)).ToList();


            //var albumToDelete = new Album(Dal.GetAlbumById(albumId));
            if (user.Albums.Any(u => u.AlbumId == albumId))
            {
                var albumToDelete = Dal.GetAlbumById(albumId);



                foreach (var img in albumToDelete.Photos)
                {
                    var      filePath = Request.MapPath(img.PhotoUrl);
                    FileInfo file     = new FileInfo(filePath);
                    if (file.Exists)
                    {
                        file.Delete();
                    }
                }



                Dal.DeleteAlbum(albumToDelete.AlbumId);
                return(RedirectToAction("Index", "Gallery"));
            }

            return(RedirectToAction("Index", "Home"));
        }
        public async Task <bool> DeleteAlbum(int id)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
            {
                throw new ApiException("You have to be logged in to modify data", 401);
            }


            var db = new AlbumRepository(context);

            return(await db.DeleteAlbum(id));
        }
示例#5
0
 public void DeleteAlbum(string albumId)
 {
     ServiceSupport.AuthorizeAndExecute(() =>
     {
         if (HttpContext.Current.IsSuperAdminLoggedIn())
         {
             // TODO: should we consider doing this cloud operation in another thread? How about a background worker?
             CloudTaskManager.PublishTask(storage =>
             {
                 storage.DeleteAlbum(albumId);
             });
             AlbumRepository.DeleteAlbum(albumId);
         }
         else
         {
             var album = AlbumRepository.FindAlbumById(albumId);
             if (album == null)
             {
                 throw new FaultException <ServerFault>(new ServerFault()
                 {
                     FaultCode = ServerFaultCode.Generic
                 },
                                                        new FaultReason("No album with Id " + albumId + " was found."));
             }
             // Only album author can delete photos
             if (!HttpContext.Current.IsUserLoggedIn(album.CreatedBy))
             {
                 throw new FaultException <ServerFault>(new ServerFault()
                 {
                     FaultCode = ServerFaultCode.NotAuthroized
                 },
                                                        new FaultReason("Album must only be deleted by the author."));
             }
             else
             {
                 // Delete photos by selected IDs and album ID
                 CloudTaskManager.PublishTask(storage =>
                 {
                     storage.DeleteAlbum(albumId);
                 });
                 AlbumRepository.DeleteAlbum(albumId);
             }
         }
     });
 }
        public async Task <string> DeleteAlbumByName(string name)
        {
            var repo = new AlbumRepository(context);

            var pks = await context.Albums.Where(alb => alb.Title == name).Select(alb => alb.Id).ToListAsync();

            StringBuilder sb = new StringBuilder();

            foreach (int pk in pks)
            {
                bool result = await repo.DeleteAlbum(pk);

                if (!result)
                {
                    sb.AppendLine(repo.ErrorMessage);
                }
            }

            return(sb.ToString());
        }
示例#7
0
        public async Task<string> DeleteAlbumByName(string name)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
                throw new ApiException("You have to be logged in to modify data", 401);

            var repo = new AlbumRepository(context);

            var pks = await context.Albums.Where(alb => alb.Title == name).Select(alb => alb.Id).ToListAsync();

            StringBuilder sb = new StringBuilder();
            foreach (int pk in pks)
            {
                bool result = await repo.DeleteAlbum(pk);
                if (!result)
                    sb.AppendLine(repo.ErrorMessage);
            }

            return sb.ToString();
        }
示例#8
0
        public async Task<bool> DeleteAlbum(int id)
        {
            if (!HttpContext.User.Identity.IsAuthenticated)
                throw new ApiException("You have to be logged in to modify data", 401);


            var db = new AlbumRepository(context);
            return await db.DeleteAlbum(id);
        }
示例#9
0
        public ActionResult DeleteAlbum(string AlbumId = "")
        {
            try
            {
                var       _photos = new List <PhotoInfo>();
                int       _albumId;
                AlbumInfo _albumInfo = null;

                if (!int.TryParse(AlbumId, out _albumId))
                {
                    TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                    return(RedirectToAction("Manage", "Gallery"));
                }

                using (var transaction = new System.Transactions.TransactionScope())
                {
                    using (AlbumRepository AlbumRepo = new AlbumRepository())
                    {
                        _albumInfo = AlbumRepo.GetAlbumById(_albumId);

                        if (_albumInfo == null)
                        {
                            TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later.");

                            return(RedirectToAction("Manage", "Gallery"));
                        }

                        using (PhotoRepository PhotoRepo = new PhotoRepository())
                        {
                            _photos = PhotoRepo.GetPhotoListByAlbumId(_albumId);

                            foreach (var item in _photos)
                            {
                                string fullPath = Request.MapPath(item.Path);

                                if (System.IO.File.Exists(fullPath))
                                {
                                    System.IO.File.Delete(fullPath);
                                }

                                PhotoRepo.DeletePhoto(item.Id);
                            }
                        }

                        string _imgPath = Server.MapPath(_albumInfo.CoverPhotoPath);

                        if (!_imgPath.Contains("default-album-cover.jpg"))
                        {
                            if (System.IO.File.Exists(_imgPath))
                            {
                                System.IO.File.Delete(_imgPath);
                            }
                        }

                        AlbumRepo.DeleteAlbum(_albumId);
                    }

                    transaction.Complete();
                }

                TempData["Msg"] = AlertMessageProvider.SuccessMessage("Album deleted successfully.");

                return(RedirectToAction("Manage", "Gallery"));
            }

            catch (Exception ex)
            {
                return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeleteAlbum")));
            }
        }
示例#10
0
        public async Task<string> DeleteAlbumByName(string name)
        {
            var repo = new AlbumRepository(context);

            var pks = await context.Albums.Where(alb => alb.Title == name).Select(alb => alb.Id).ToListAsync();

            StringBuilder sb = new StringBuilder();
            foreach (int pk in pks)
            {
                bool result = await repo.DeleteAlbum(pk);
                if (!result)
                    sb.AppendLine(repo.ErrorMessage);
            }

            return sb.ToString();
        }
示例#11
0
 public async Task<bool> DeleteAlbum(int id)
 {
     var db = new AlbumRepository(context);
     return await db.DeleteAlbum(id);
 }
        public async Task <bool> DeleteAlbum(int id)
        {
            var db = new AlbumRepository(context);

            return(await db.DeleteAlbum(id));
        }