public async Task <IActionResult> Delete(DropBoxItems s) { bool formatExists = false; String format = s.Format; await dropbox.Files.DeleteV2Async(s.Path); itemsRepository.Delete(s); foreach (DropBoxItems i in itemsRepository.GetAll()) { if (format.Equals(i.Format)) { formatExists = true; break; } } if (formatExists == false) { foreach (DropBoxCategory c in categoryRepository.GetAll()) { if (format.Equals(c.CategoryType)) { categoryRepository.Delete(c); } } } return(RedirectToAction("Index")); }
public void Delete(DropBoxItems s) { DropBoxItems items = _db.DropBoxItems.Find(s.ItemID); _db.DropBoxItems.Remove(items); _db.SaveChanges(); }
// Update public IActionResult Update(int id) { DropBoxItems item = itemsRepository.Get(id); //ivm.Items = itemsRepository.Get(id); return(View(item)); }
public async Task <FileResult> Download(int id) { DropBoxItems item = itemsRepository.Get(id); //byte[] fileBytes = System.IO.File.ReadAllBytes(item.Path); //string fileName = item.Title+item.Format; string path = item.Path; string fileName = ""; char[] aux = path.ToCharArray(); for (int i = aux.Count() - 1; i > 0; i--) { if (aux[i] == '/' || aux[i] == '\\') { i = 0; } else { fileName = aux[i] + fileName; } } using (var response = await dropbox.Files.DownloadAsync(path)) { //Console.WriteLine(await response.GetContentAsStringAsync()); return(File(await response.GetContentAsByteArrayAsync(), "application/x-msdownload", fileName)); } }
public DropBoxItems GetLastItem() { DropBoxItems item = new DropBoxItems(); foreach (DropBoxItems i in _db.DropBoxItems) { item = i; } return(item); }
public IActionResult Update(DropBoxItems c) { if (ModelState.IsValid) { itemsRepository.Delete(c); c.date = System.DateTime.UtcNow.ToString(); itemsRepository.Save(c); return(RedirectToAction("Index")); } else { return(View()); } }
/*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 IActionResult Delete(int id) { DropBoxItems i = itemsRepository.Get(id); return(View(i)); }
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 void Update(DropBoxItems Items) { _db.DropBoxItems.Update(Items); _db.SaveChanges(); }
public void Save(DropBoxItems items) { _db.DropBoxItems.Add(items); _db.SaveChanges(); }
public DropBoxItems Get(int id) { DropBoxItems items = _db.DropBoxItems.AsNoTracking().Where(r => r.ItemID == id).FirstOrDefault(); return(items); }