Ejemplo n.º 1
0
        public async Task <IActionResult> Delete(int id)
        {
            CollectionModel col = await _collectionRepository.GetCollectionById(id);

            await _collectionRepository.Delete(id);

            return(RedirectToAction(nameof(AddNewCollection), new { isSuccess = true, projectId = col.ProjectsID }));
        }
        public IActionResult OnPostDelete(int id)
        {
            CollectionRepository collectionRepository = new CollectionRepository();

            try
            {
                collectionRepository.Delete(id);
            }
            catch (Exception)
            {
                Message          = "The try to delete collection was incorrect!";
                IsWarningMessage = true;
            }
            return(RedirectToPage());
        }
        public void User_Can_Delete_Collection()
        {
            // Get an object that's in the database
            var collectionToAdd = new Collection()
            {
                UserId           = 1,
                CategorizationId = 1,
                Name             = "New Collection to Axe",
                Description      = "Blah",
                Pinned           = false,
                CreationDate     = DateTime.Now - TimeSpan.FromDays(15)
            };

            // Add collectionToAdd to collectionDetailsVm
            var collectionDetails = new CollectionDetailsViewModel
            {
                Collection         = collectionToAdd,
                ProjectCollections = new List <ProjectCollection>(),
                Words = new List <Word>()
            };

            // Instantiate CollectionRepo
            var repo = new CollectionRepository(_context);

            // Get a count of Collections for UserId 1
            var count = repo.Get(1).Count;

            // Add new collection
            repo.Add(collectionToAdd);

            // Get a new count
            var countAfterAdd = repo.Get(1).Count;

            // Attempt to delete the collection
            repo.Delete(collectionDetails);

            // New count after deleting
            var countAfterDeletion = repo.Get(1).Count;

            // We successfully added one collection
            Assert.True(count < countAfterAdd);
            // We successfully deleted one collection
            Assert.True(count == countAfterDeletion);
        }
Ejemplo n.º 4
0
        //Do these delete methods need to be secured?
        public void DeleteAllUserCollections()
        {
            IEnumerable <Collection> collections = CollectionRepository.Find(c => c.Type == CollectionType.USER);

            var collectionPath = ValidateAndGetUserCollectionPath();

            foreach (var col in collections)
            {
                string filePath = Path.Combine(collectionPath, col.ContainerID);

                if (System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.Delete(filePath, true);
                }

                CollectionRepository.Delete(col);
                Unit.Commit();
            }
        }
Ejemplo n.º 5
0
        public bool DeleteUserCollection(long currentUserId, long collectionID)
        {
            Collection col = CollectionRepository.First(c => c.ID == collectionID && c.Owner.ID == currentUserId && c.Type != CollectionType.SITE);

            if (col != null)
            {
                string filePath = Path.Combine(ValidateAndGetUserCollectionPath(), col.ContainerID);

                if (System.IO.Directory.Exists(filePath))
                {
                    System.IO.Directory.Delete(filePath, true);
                }

                CollectionRepository.Delete(col);
                Unit.Commit();

                return(true);
            }

            return(false);
        }
 public IActionResult Delete(int id)
 {
     _collectionRepository.Delete(id);
     return(NoContent());
 }