Example #1
0
        public ActionResult Edit(docs docs)
        {
            docs original = db.docs.Find(docs.id_archivo);

            try
            {
                if (ModelState.IsValid)
                {
                    original.nombre = docs.nombre;
                    if (docs.categoria != null)
                    {
                        original.categoria = docs.categoria;
                    }
                    original.autor = docs.autor;
                    if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                    {
                        var    file    = Request.Files[0];
                        string archivo = (DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + file.FileName).ToLower();
                        original.dir_archivo = archivo;
                        file.SaveAs(Server.MapPath("~/subidas/archivos/" + archivo));
                    }
                    db.Entry(original).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(original));
            }
            catch (Exception e) {
                return(RedirectToAction("index"));
            }
        }
Example #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            docs docs = db.docs.Find(id);

            db.docs.Remove(docs);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #3
0
        public ActionResult Index(HttpPostedFileBase file, docs doc)
        {
            //foreach(string in box.Download)
            List <string> files = new List <string>();
            Sharepoint    share = new Sharepoint();

            TempData["sharepointFiles"] = share.pull(); //downloading all of the files from sharepoint and storing names locally
            return(RedirectToAction("BoxAsync"));
        }
Example #4
0
        //recursive function that pulls all files from all folders
        public async Task <List <string> > searchFolder(BoxClient client, BoxCollection <BoxItem> items, string BoxURL)
        {
            List <string> files     = new List <string>();                                                          //stores the file names for future display
            List <string> tempFiles = new List <string>();
            int           id        = 0;                                                                            //temp placeholder for id

            foreach (BoxItem item in items.Entries)                                                                 //loop through all items in a folder
            {
                if (item.Type == "folder")                                                                          //if the item is a folder dive into it
                {
                    BoxCollection <BoxItem> folder = await client.FoldersManager.GetFolderItemsAsync(item.Id, 500); //get files from new folder

                    tempFiles = await searchFolder(client, folder, BoxURL);                                         //recursive call

                    foreach (string i in tempFiles)                                                                 //load file names into list
                    {
                        files.Add(i);
                    }
                    continue; //skip to next item
                }

                //converts the box field id from string to int
                Int32.TryParse(item.Id.Substring(item.Id.Length - 5, 4), out id);       //id is actually a long so for our purposes i just grabbed some of it
                Stream stream = await client.FilesManager.DownloadStreamAsync(item.Id); //grab the actual file

                docs elasticSearch = new docs();                                        //build elasticSearch Connection

                byte[] data;
                byte[] buffer = new byte[1024 * 64];
                using (MemoryStream ms = new MemoryStream()) //grab file stream and pass it into elasticsearch
                {
                    int count = 0;
                    do
                    {
                        count = stream.Read(buffer, 0, buffer.Length);
                        ms.Write(buffer, 0, count);
                    } while (count > 0);
                    data = ms.ToArray();
                    FileMeta tempFile = new FileMeta();

                    tempFile.Path   = BoxURL + item.Id;
                    tempFile.File   = data;               //load metadata for elasticsearch
                    tempFile.Id     = id;                 //load metadata for elasticsearch
                    tempFile.Name   = item.Name;          //load metadata for elasticsearch
                    tempFile.longID = item.Id;
                    elasticSearch.uploadDirect(tempFile); //upload the file in memory stream to elasticsearch as id of j
                }
                files.Add(item.Name);                     //append the name of the file to the list for future display on results page
            }
            return(files);                                //return a list of all files
        }
Example #5
0
        // GET: docs/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            docs docs = db.docs.Find(id);

            if (docs == null)
            {
                return(HttpNotFound());
            }
            return(View(docs));
        }
Example #6
0
        // GET: docs/Edit/5
        public ActionResult Edit(int?id)
        {
            ViewBag.categoria = new SelectList(holi, "id", "nombre");
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            docs docs = db.docs.Find(id);

            if (docs == null)
            {
                return(HttpNotFound());
            }
            return(View(docs));
        }
Example #7
0
        public ActionResult Create(docs docs)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0)
                    {
                        var    file    = Request.Files[0];
                        string archivo = (DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + file.FileName).ToLower();
                        docs.dir_archivo = archivo;
                        file.SaveAs(Server.MapPath("~/subidas/archivos/" + archivo));
                    }
                    db.docs.Add(docs);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(docs));
            }
            catch (Exception e) {
                return(RedirectToAction("Create"));
            }
        }