コード例 #1
0
        public async Task <IActionResult> DeleteDB(ICollection <int> iDs)
        {
            foreach (var id in iDs)
            {
                bool         formatExists = false;
                DropBoxItems s            = itemsRepositoryDB.Get(id);
                String       format       = s.Format;
                await dropbox.Files.DeleteV2Async(s.Path);

                itemsRepositoryDB.Delete(s);

                foreach (DropBoxItems i in itemsRepositoryDB.GetAll())
                {
                    if (format.Equals(i.Format))
                    {
                        formatExists = true;
                        break;
                    }
                }
                if (formatExists == false)
                {
                    foreach (DropBoxCategory c in categoryRepositoryDB.GetAll())
                    {
                        if (format.Equals(c.CategoryType))
                        {
                            categoryRepositoryDB.Delete(c);
                        }
                    }
                }
            }

            return(RedirectToAction("IndexDB"));
        }
コード例 #2
0
        public DropBoxController(ICategoryRepositoryDB categoryRepository, IItemsRepositoryDB itemsRepository, IHostingEnvironment env)
        {
            this.categoryRepository = categoryRepository;
            this.itemsRepository    = itemsRepository;
            //auxCivm.Categories = categoryRepository.GetAll().ToList();
            auxCivm.Categories = categoryRepository.GetAll().ToList();
            auxCivm.Items      = itemsRepository.GetAll().ToList();
            var task = Task.Run((Func <Task>)DropBoxController.Run);

            civm.GroupTags = new List <String>();
            task.Wait();
            if (task.IsCompleted)
            {
                try{
                    foreach (DropBoxCategory c in auxCivm.Categories)
                    {
                        categoryRepository.Save(c);
                    }
                    foreach (DropBoxItems i in auxCivm.Items)
                    {
                        itemsRepository.Save(i);
                    }
                    foreach (DropBoxCategory c in auxCivmRemove.Categories)
                    {
                        categoryRepository.Delete(c);
                    }
                    foreach (DropBoxItems i in auxCivmRemove.Items)
                    {
                        itemsRepository.Delete(i);
                    }
                }catch (Exception e)
                {
                }
                civm.Categories = categoryRepository.GetAll().ToList();
                civm.Items      = itemsRepository.GetAll();
                ivm.Categories  = categoryRepository.GetAll().ToList();
                this.hostingEnv = env;
            }
        }
コード例 #3
0
        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"));
            }
        }