Ejemplo n.º 1
0
        public async Task <IActionResult> DeleteFolder(DeleteFolderAddressModel model)
        {
            var folders = _folderLocator.SplitStrings(model.FolderNames);
            var folder  = await _folderLocator.LocateSiteAndFolder(model.AccessToken, model.SiteName, folders);

            if (folder.ContextId == null)
            {
                return(this.Protocol(ErrorType.NotEnoughResources, "We can not delete root folder! If you wanna delete your site, please consider delete your site directly!"));
            }
            await _folderCleaner.DeleteFolderAsync(folder);

            await _dbContext.SaveChangesAsync();

            return(this.Protocol(ErrorType.Success, "Successfully deleted your folder!"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> DeleteSite(DeleteSiteAddressModel model)
        {
            var appid = _tokenManager.ValidateAccessToken(model.AccessToken);
            var site  = await _dbContext
                        .Sites
                        .Include(t => t.Root)
                        .SingleOrDefaultAsync(t => t.SiteName == model.SiteName);

            if (site == null)
            {
                return(this.Protocol(ErrorType.NotFound, $"Could not find a site with name: '{model.SiteName}'"));
            }
            if (site.AppId != appid)
            {
                return(this.Protocol(ErrorType.Unauthorized, $"The site you tried to delete is not your app's site."));
            }
            await _folderCleaner.DeleteFolderAsync(site.Root);

            _dbContext.Sites.Remove(site);
            await _dbContext.SaveChangesAsync();

            return(this.Protocol(ErrorType.Success, "Successfully deleted your site!"));
        }