//
        //GET: Home/Index

        public ActionResult Index()
        {
            FileListViewModel    flvm    = new FileListViewModel();
            FileBusinessLayer    fbl     = new FileBusinessLayer();
            List <FileDB>        files   = fbl.GetFiles();
            List <FileViewModel> evmlist = new List <FileViewModel>();

            foreach (FileDB file in files)
            {
                if (!file.isDelete)
                {
                    FileViewModel fvm = new FileViewModel();
                    fvm.FileId     = file.FileId;
                    fvm.FileName   = file.FileName;
                    fvm.Creater    = file.Creater;
                    fvm.UploadTime = file.UploadTime;
                    fvm.Version    = file.Version;
                    evmlist.Add(fvm);
                }
            }

            flvm.FileList   = evmlist;
            flvm.Permission = Convert.ToString(Session["Permission"]);
            return(View("Index", flvm));
        }
        public ActionResult Details(int id)
        {
            FileBusinessLayer fbl  = new FileBusinessLayer();
            FileDB            file = fbl.GetFile(id);

            if (file == null)
            {
                return(HttpNotFound());
            }

            FileViewModel fvm = new FileViewModel();

            fvm.FileId       = file.FileId;
            fvm.FileName     = file.FileName;
            fvm.Creater      = file.Creater;
            fvm.Version      = file.Version;
            fvm.UploadTime   = file.UploadTime;
            fvm.ModifiedTime = file.ModifiedTime;
            if (file.FilePath != "")
            {
                fvm.FileContent = System.IO.File.ReadAllText(Path.Combine(_uploadsFolder, file.FilePath));
            }
            else
            {
                fvm.FileContent = "File content is empty. Please check the file path!";
            }
            return(View("Details", fvm));
        }
        public ActionResult History(int id)
        {
            FileListViewModel    flvm    = new FileListViewModel();
            FileBusinessLayer    fbl     = new FileBusinessLayer();
            List <FileDB>        files   = fbl.GetFiles();
            List <FileViewModel> evmlist = new List <FileViewModel>();

            FileDB filenow = fbl.GetFile(id);

            while (filenow != null)
            {
                FileViewModel fvm = new FileViewModel();
                fvm.FileId      = filenow.FileId;
                fvm.FileName    = filenow.FileName;
                fvm.Creater     = filenow.Creater;
                fvm.UploadTime  = filenow.UploadTime;
                fvm.Version     = filenow.Version;
                fvm.FileContent = filenow.FilePath;
                evmlist.Add(fvm);
                filenow = filenow.FormerId;
            }

            flvm.FileList   = evmlist;
            flvm.Permission = Convert.ToString(Session["Permission"]);
            return(View("Historys", flvm));
        }
Beispiel #4
0
        public ActionResult Index()
        {
            FileListViewModel elvm  = new FileListViewModel();
            FileBusinessLayer fbl   = new FileBusinessLayer();
            List <FileDB>     files = fbl.GetFiles();

            List <FileViewModel> evmlist = new List <FileViewModel>();

            foreach (FileDB file in files)
            {
                if (!file.isDelete)
                {
                    FileViewModel fvm = new FileViewModel();
                    fvm.FileId     = file.FileId;
                    fvm.FileName   = file.FileName;
                    fvm.Creater    = file.Creater;
                    fvm.UploadTime = file.UploadTime;
                    fvm.Version    = file.Version;
                    evmlist.Add(fvm);
                }
            }

            elvm.FileList = evmlist;
            elvm.UserName = "******";

            return(View("Index", elvm));
        }
Beispiel #5
0
        public ActionResult Edit(int id = 0)
        {
            FileBusinessLayer fbl  = new FileBusinessLayer();
            FileDB            file = fbl.GetFile(id);

            return(View("Edit", new CreateFileViewModel()));
        }
Beispiel #6
0
        public ActionResult Details(int id)
        {
            FileBusinessLayer fbl  = new FileBusinessLayer();
            FileDB            file = fbl.GetFile(id);

            if (file == null)
            {
                return(JavaScript("Error" + id));
            }

            DisplayFileViewModel pfvm = new DisplayFileViewModel();

            pfvm.FileName     = file.FileName;
            pfvm.Creater      = file.Creater;
            pfvm.Version      = file.Version;
            pfvm.UploadTime   = file.UploadTime;
            pfvm.ModifiedTime = file.ModifiedTime;
            if (file.FilePath != "")
            {
                pfvm.FileContent = System.IO.File.ReadAllText(file.FilePath);
            }
            else
            {
                pfvm.FileContent = "File content is empty. Please check the file path!";
            }
            return(View("Details", pfvm));
        }
        //
        //GET: /Home/SearchIndex

        public ActionResult SearchIndex(string keyword)
        {
            FileBusinessLayer fbl = new FileBusinessLayer();
            var files             = from f in fbl.GetFiles() select f;

            if (!String.IsNullOrEmpty(keyword))
            {
                files = files.Where(s => s.FileName.Contains(keyword));
            }
            return(View("SearchIndex", files));
        }
        public ActionResult ConfirmDelete(FormCollection fcNotUsed, int id)
        {
            FileBusinessLayer fbl  = new FileBusinessLayer();
            FileDB            file = fbl.GetFile(id);

            if (file == null)
            {
                return(HttpNotFound());
            }
            //System.IO.File.Delete(file.FilePath);
            fbl.SaveFile(file, "delete");
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(FormCollection fcNotUsed, int id)
        {
            FileBusinessLayer fbl  = new FileBusinessLayer();
            FileDB            file = fbl.GetFile(id);

            if (file == null)
            {
                return(HttpNotFound());
            }

            fbl.SaveFile(file, "mark delete");
            return(RedirectToAction("Index"));
        }
Beispiel #10
0
        public ActionResult Delete(FormCollection fcNotUsed, int id)
        {
            FileBusinessLayer fbl  = new FileBusinessLayer();
            FileDB            file = fbl.GetFile(id);

            if (file == null)
            {
                return(HttpNotFound());
            }

            file.ModifiedTime = DateTime.Now;
            file.isDelete     = true;

            fbl.SaveFile(file);

            return(RedirectToAction("Index"));
        }
        public ActionResult Edit()
        {
            int FileId = int.Parse(Request["FileId"]);

            System.Diagnostics.Debug.Write(FileId);
            string FileName    = Request["FileName"];
            int    FileVersion = int.Parse(Request["FileVersion"]);
            string FileContent = Request["FileContent"];

            FileDB file = new FileDB();

            file.FileId   = FileId;
            file.FileName = FileName;
            file.FilePath = fileTime + "_" + FileVersion + "_" + FileName;
            file.Creater  = User.Identity.Name;
            file.Version  = FileVersion;

            FileStream   fs = new FileStream(Path.Combine(_uploadsFolder, file.FilePath), FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            sw.Write(FileContent);
            sw.Flush();
            sw.Close();
            fs.Close();

            FileBusinessLayer fbl = new FileBusinessLayer();

            fbl.SaveFile(file, "modify");

            var result = new { err = false, message = "no err" };

            return(Json(result));

            /*
             * catch
             * {
             * var result = new { err = true, message = "save file err" };
             * return Json(result);
             * }
             * */
        }
        public ActionResult SaveFile(string fileName, HttpPostedFileBase uploadFile)
        {
            if (uploadFile != null && fileName != null)
            {
                FileDB file = new FileDB();
                file.FileName = fileName;
                file.Creater  = User.Identity.Name;
                file.FilePath = uploadFile.FileName;
                uploadFile.SaveAs(Path.Combine(_uploadsFolder, file.FilePath));

                FileBusinessLayer fbl = new FileBusinessLayer();
                fbl.SaveFile(file, "upload");
                return(RedirectToAction("Index"));
            }
            else
            {
                FileViewModel fvm = new FileViewModel();
                fvm.FileName = fileName;
                return(View("Upload", fvm));
            }
        }
Beispiel #13
0
        public ActionResult SaveFile(FileDB file, string BtnSubmit, HttpPostedFileBase UploadFile)
        {
            if (UploadFile != null)
            {
                switch (BtnSubmit)
                {
                case "Save File":

                    file.FilePath = Path.Combine(_uploadsFolder, UploadFile.FileName);
                    UploadFile.SaveAs(file.FilePath);

                    file.Creater      = "Admin";
                    file.UploadTime   = DateTime.Now;
                    file.ModifiedTime = DateTime.Now;
                    file.Version      = 1;
                    file.isDelete     = false;

                    FileBusinessLayer fbl = new FileBusinessLayer();
                    fbl.SaveFile(file);

                    return(RedirectToAction("Index"));

                //if (ModelState.IsValid) { }
                //else
                //{
                //    CreateFileViewModel cfvm = new CreateFileViewModel();
                //    cfvm.FileName = file.FileName;
                //    return View("CreateFile", cfvm);
                //}

                case "Cancel":
                    return(RedirectToAction("Index"));

                default:
                    return(RedirectToAction("CreateFile", new CreateFileViewModel()));
                }
            }
            return(Content("Upload Error! File is empty"));
        }
        public ActionResult VersionCompare()
        {
            int v1 = int.Parse(Request["v1"]);
            int v2 = int.Parse(Request["v2"]);
            FileBusinessLayer fbl = new FileBusinessLayer();
            FileDB            f1  = fbl.GetFile(v1);
            FileDB            f2  = fbl.GetFile(v2);

            FileStream   fs1      = new FileStream(Path.Combine(_uploadsFolder, f1.FilePath), FileMode.Open);
            FileStream   fs2      = new FileStream(Path.Combine(_uploadsFolder, f2.FilePath), FileMode.Open);
            StreamReader sr1      = new StreamReader(fs1);
            StreamReader sr2      = new StreamReader(fs2);
            string       content1 = sr1.ReadLine();

            while (content1.Trim() == null || content1.Trim().Equals(""))
            {
                content1 = sr1.ReadLine();
            }

            string content2 = sr2.ReadLine();

            while (content2.Trim() == null || content2.Trim().Equals(""))
            {
                content2 = sr2.ReadLine();
            }

            string DiffContent = "\n";
            int    line        = 1;

            while (!sr1.EndOfStream || !sr2.EndOfStream)
            {
                System.Diagnostics.Debug.Write(content1);
                System.Diagnostics.Debug.Write(content2);

                if (sr1.EndOfStream)
                {
                    DiffContent += "In Line No." + line + ": " + "\n"
                                   + "         Version" + f1.Version + ": " + "File End." + "\n"
                                   + "         Version" + f2.Version + ": " + content2 + "\n\n";
                }
                else if (sr2.EndOfStream)
                {
                    DiffContent += "In Line No." + line + ": " + "\n"
                                   + "         Version" + f1.Version + ": " + content1 + "\n"
                                   + "         Version" + f2.Version + ": " + "File End." + "\n\n";
                }
                else if (!content1.Equals(content2))
                {
                    DiffContent += "In Line No." + line + ": " + "\n"
                                   + "         Version" + f1.Version + ": " + content1 + "\n"
                                   + "         Version" + f2.Version + ": " + content2 + "\n\n";
                }

                if (!sr1.EndOfStream)
                {
                    content1 = sr1.ReadLine();
                }
                if (!sr2.EndOfStream)
                {
                    content2 = sr2.ReadLine();
                }
                line++;
            }

            sr1.Close();
            sr2.Close();
            fs1.Close();
            fs2.Close();

            VersionViewModel vvm = new VersionViewModel();

            vvm.FirstVersion  = f1;
            vvm.SecondVersion = f2;
            vvm.DiffContent   = DiffContent;

            return(View("Versions", vvm));
        }