public void Delete(DropBoxCategory s) { DropBoxCategory category = _db.DropBoxCategory.Find(s.CategoryID); _db.DropBoxCategory.Remove(category); _db.SaveChanges(); }
/*static async Task Run() * { * using (var dbx = new DropboxClient("MgX6Ia7UK1AAAAAAAAAACUxEgjuhsT4DtHykvshYVhkO5EtLqHoZOvPVuG4NJ-L2")) * { * var full = await dbx.Users.GetCurrentAccountAsync(); * Console.WriteLine(full.Email); * await ListRootFolder(dbx, context); * //await Download(dbx,"","Get Started with Dropbox.pdf"); * } * }*/ static async Task ListRootFolder(DropboxClient dbx, MyDbContext context) { List <DropBoxCategory> categories = new List <DropBoxCategory>(); var list = await dbx.Files.ListFolderAsync(string.Empty); foreach (var file in list.Entries.Where(i => i.IsFile)) { bool cExist = false; DropBoxItems item = new DropBoxItems(); String fName = file.Name; String aux = fName.Substring(0, (fName.IndexOf('.'))); String form = fName.Substring(fName.IndexOf('.'), (fName.Length - fName.IndexOf('.'))); //item = new Items{Title=aux,Format=form, Path=Path.Combine(uploads,file.FileName),date=System.DateTime.Now.ToString()}; item.Title = aux; item.Format = form; item.date = System.DateTime.UtcNow.ToString(); item.Tags = "DropBoxFile"; item.Path = "/" + fName; var author = await dbx.Users.GetCurrentAccountAsync(); item.Author = author.Name.ToString(); context.DropBoxItems.Add(item); DropBoxCategory category = new DropBoxCategory { CategoryType = form }; categories.Add(category); for (int i = 0; i < (categories.Count() - 1) && (cExist == false); i++) { if (categories[i].CategoryType.Equals(form)) { cExist = true; categories.Remove(categories[i]); } } if (cExist == false) { context.DropBoxCategory.Add(category); } } }
public async Task <IActionResult> Post(ICollection <IFormFile> files, DropBoxItems item) { if (ModelState.IsValid) { var uploads = Path.Combine(hostingEnv.WebRootPath, "Files"); foreach (var file in files) { if (file.Length > 0) { using (var fileStream = new FileStream(Path.Combine(uploads, file.FileName), FileMode.Create)) { await file.CopyToAsync(fileStream); } var path = Path.Combine(uploads, file.FileName); using (var mem = new FileStream(path, FileMode.Open)) { bool cExist = false; bool fExist = false; String fName = file.FileName; String aux = fName.Substring(0, (fName.IndexOf('.'))); String form = fName.Substring(fName.IndexOf('.'), (fName.Length - fName.IndexOf('.'))); item.Title = aux; item.Format = form; item.date = System.DateTime.UtcNow.ToString(); item.Path = "/Uploads/" + file.FileName; item.Link = "https://www.dropbox.com/home/Uploads?preview="; String lPath = ""; char[] lAux = (item.Title + item.Format).ToCharArray(); foreach (var c in lAux) { if (c == ' ') { lPath = lPath + "+"; } else { lPath = lPath + c; } } item.Link = item.Link + lPath; foreach (DropBoxCategory c in categoryRepository.GetAll()) { if (c.CategoryType.Equals(form)) { cExist = true; break; } } if (cExist == false) { DropBoxCategory category = new DropBoxCategory { CategoryType = form }; categoryRepository.Save(category); } foreach (DropBoxItems i in itemsRepository.GetAll()) { if (i.Title.Equals(item.Title)) { fExist = true; itemsRepository.Delete(i); itemsRepository.Save(item); await dropbox.Files.DeleteV2Async(i.Path); break; } } if (fExist == false) { itemsRepository.Save(item); } await dropbox.Files.UploadAsync( "/Uploads" + "/" + file.FileName, WriteMode.Overwrite.Instance, body : mem); } System.IO.File.Delete(path); } } return(RedirectToAction("Index")); } else { return(RedirectToAction("Upload")); } }
static async Task <CategoriesItemsViewModelDB> ListRootFolder(DropboxClient dbx) { HttpClientHandler handler = new HttpClientHandler(); using (var client = new HttpClient(handler, false)) { CategoriesItemsViewModelDB catItems = new CategoriesItemsViewModelDB(); List <DropBoxItems> items = new List <DropBoxItems>(); List <DropBoxCategory> categories = new List <DropBoxCategory>(); var list = await dbx.Files.ListFolderAsync(string.Empty); foreach (var folder in list.Entries.Where(i => i.IsFolder)) { var cFolder = await dbx.Files.ListFolderAsync("/" + folder.Name); foreach (var file in cFolder.Entries.Where(i => i.IsFile)) { bool cExist = false; DropBoxItems item = new DropBoxItems(); String fName = file.Name; String aux = fName.Substring(0, (fName.IndexOf('.'))); String form = fName.Substring(fName.IndexOf('.'), (fName.Length - fName.IndexOf('.'))); //item = new Items{Title=aux,Format=form, Path=Path.Combine(uploads,file.FileName),date=System.DateTime.UtcNow.ToString()}; item.Title = aux; item.Format = form; item.date = System.DateTime.UtcNow.ToString(); item.Tags = folder.Name; item.Path = file.PathDisplay; //To be replaced //var author = await dbx.Users.GetCurrentAccountAsync(); //item.Author = author.Email.ToString(); item.Author = "DropBox User"; if (!item.Tags.Equals("/")) { item.Link = "https://www.dropbox.com/home/" + item.Tags + "?preview="; } else { item.Link = "https://www.dropbox.com/home?preview="; } String lPath = ""; char[] lAux = (item.Title + item.Format).ToCharArray(); foreach (var c in lAux) { if (c == ' ') { lPath = lPath + "+"; } else { lPath = lPath + c; } } item.Link = item.Link + lPath; items.Add(item); DropBoxCategory category = new DropBoxCategory { CategoryType = form }; for (int i = 0; i < (categories.Count()) && (cExist == false); i++) { if (categories[i].CategoryType.Equals(form)) { cExist = true; } } if (cExist == false) { categories.Add(category); } } } foreach (var file in list.Entries.Where(i => i.IsFile)) { bool cExist = false; DropBoxItems item = new DropBoxItems(); String fName = file.Name; String aux = fName.Substring(0, (fName.IndexOf('.'))); String form = fName.Substring(fName.IndexOf('.'), (fName.Length - fName.IndexOf('.'))); //item = new Items{Title=aux,Format=form, Path=Path.Combine(uploads,file.FileName),date=System.DateTime.UtcNow.ToString()}; item.Title = aux; item.Format = form; item.date = System.DateTime.UtcNow.ToString(); item.Tags = file.PathDisplay.Substring(0, (file.PathDisplay.IndexOf(file.Name[0]))); item.Path = file.PathDisplay; //var author = await dbx.Users.GetCurrentAccountAsync(); //item.Author = author.Email.ToString(); item.Author = "DropBox User"; if (!item.Tags.Equals("/")) { item.Link = "https://www.dropbox.com/home/" + item.Tags + "?preview="; } else { item.Link = "https://www.dropbox.com/home?preview="; } String lPath = ""; char[] lAux = (item.Title + item.Format).ToCharArray(); foreach (var c in lAux) { if (c == ' ') { lPath = lPath + "+"; } else { lPath = lPath + c; } } item.Link = item.Link + lPath; items.Add(item); DropBoxCategory category = new DropBoxCategory { CategoryType = form }; for (int i = 0; i < (categories.Count()) && (cExist == false); i++) { if (categories[i].CategoryType.Equals(form)) { cExist = true; } } if (cExist == false) { categories.Add(category); } } catItems.Categories = categories; catItems.Items = items; return(catItems); } }
public DropBoxCategory GetByName(string s) { DropBoxCategory category = _db.DropBoxCategory.Where(r => r.CategoryType.Equals(s)).FirstOrDefault(); return(category); }
public void Update(DropBoxCategory category) { _db.DropBoxCategory.Update(category); _db.SaveChanges(); }
public void Save(DropBoxCategory category) { _db.DropBoxCategory.Add(category); _db.SaveChanges(); }
public DropBoxCategory Get(int id) { DropBoxCategory category = _db.DropBoxCategory.Where(r => r.CategoryID == id).FirstOrDefault(); return(category); }