Exemplo n.º 1
0
        public bool DeleteSnippet(string hash)
        {
            var snippet = _snippetRepository.GetSnippetByHash(hash);

            if (snippet == null)
            {
                return(false);
            }

            //foreach user check if he has this snippet shared
            var users = _userRepository.GetUsers();

            foreach (var user in users)
            {
                if (user.SharedSnippets.Any(x => x.Hash == hash))
                {
                    user.SharedSnippets.RemoveAll(x => x.Hash == hash);
                    _userRepository.UpdateUser(user);
                }
            }

            _snippetRepository.DeleteSnippet(snippet.Id);

            return(true);
        }
Exemplo n.º 2
0
        public ActionResult DeleteSnippet(int snippetId)
        {
            var snippet = _snipRepo.Snippets.FirstOrDefault(s => s.SnippetId == snippetId);

            if (snippet != null)
            {
                var snippetName = snippet.Name;
                _snipRepo.DeleteSnippet(snippet);
                TempData["message"] = string.Format("{0} has been deleted!", snippetName);
                return(RedirectToAction("List"));
            }
            TempData["message"] = string.Format("Nothing found for ID {0}!", snippetId);
            return(RedirectToAction("List"));
        }
Exemplo n.º 3
0
        public bool DeleteSnippet(string hash)
        {
            var snippet = _snippetRepository.GetSnippetByHash(hash);

            if (snippet == null)
            {
                return(false);
            }
            foreach (var file in snippet.Files)
            {
                _snippetFileRepository.DeleteSnippetFile(file.Id);
            }
            _snippetRepository.DeleteSnippet(snippet.Id);
            return(true);
        }