コード例 #1
0
        public ActionResult DeleteFile()
        {
            DeleteFileModel tempdatafile = (DeleteFileModel)Session["FileDelete"];
            var             deleteFile   = db.Document_Repository.Where(f => f.Document_Seq.Equals(tempdatafile.Document_Seq)).FirstOrDefault();

            var sessionLog = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(p => p.Login_DateTime).FirstOrDefault();

            Document_Access_Log ac = new Document_Access_Log();

            ac.Access_DateTime = DateTime.Now;
            ac.Document_Seq    = deleteFile.Document_Seq;
            ac.Session_ID      = sessionLog.Session_ID;

            db.Document_Access_Log.Add(ac);
            db.SaveChanges();

            //record action
            global.addAudit("Repository", "Repository: Delete File", "Delete", User.Identity.Name);

            deleteFile.Document_Status = "Deleted";
            var virtualDirectoryPath = deleteFile.Directory_Path;

            if (System.IO.File.Exists(virtualDirectoryPath))
            {
                System.IO.File.Delete(virtualDirectoryPath);
            }
            db.Entry(deleteFile).State = EntityState.Modified;
            db.SaveChanges();
            TempData["Message"]    = "File '" + deleteFile.Document_Name + "' successfuly deleted";
            TempData["classStyle"] = "success";
            Session.Remove("FileDelete");
            return(RedirectToAction("ViewFile"));
        }
コード例 #2
0
        public FilePathResult DownloadFile(int id)
        {
            var file = db.Document_Repository.Where(f => f.Document_Seq.Equals(id)).FirstOrDefault();

            var sessionLog = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(p => p.Login_DateTime).FirstOrDefault();

            Document_Access_Log ac = new Document_Access_Log();

            ac.Access_DateTime = DateTime.Now;
            ac.Document_Seq    = file.Document_Seq;
            ac.Session_ID      = sessionLog.Session_ID;

            db.Document_Access_Log.Add(ac);
            db.SaveChanges();

            var virtualDirectoryPath = file.Directory_Path;

            return(File(virtualDirectoryPath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(virtualDirectoryPath)));
        }
コード例 #3
0
        public ActionResult AddFile(AddFileModel model)
        {
            //check if model state is valid
            if (ModelState.IsValid)
            {
                //get uploaded file filename
                var filename = Path.GetFileName(model.uploadFile.FileName);
                //get uploaded file path
                var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), filename);
                //determine the uploaded file extension
                var extension = Path.GetExtension(model.uploadFile.FileName);
                //check if the file uploaded is a valid extension
                if (System.IO.File.Exists(path))
                {
                    TempData["Message"]      = "Uploaded file already exists";
                    TempData["classStyle"]   = "warning";
                    model.uploadFile         = null;
                    ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
                    ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
                    return(View(model));
                }
                else
                {
                    var validExtension = db.Document_Extension.Where(m => m.Extension_Type.Equals(extension)).FirstOrDefault();
                    if (validExtension != null)
                    {
                        //create a new instance of a document_repository object
                        Document_Repository a = new Document_Repository();
                        //add details of the file to a document_repository object
                        a.Document_Name         = model.Document_Name;
                        a.Description           = model.Description;
                        a.Category_ID           = model.Category_ID;
                        a.Document_Type_ID      = model.Document_Type_ID;
                        a.Directory_Path        = path;
                        a.Document_Extension_ID = validExtension.Document_Extension_ID;
                        a.Document_Status       = "Active";
                        db.Document_Repository.Add(a);
                        db.SaveChanges();

                        var sessionLog = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(p => p.Login_DateTime).FirstOrDefault();

                        Document_Access_Log ac = new Document_Access_Log();
                        ac.Access_DateTime = DateTime.Now;
                        ac.Document_Seq    = a.Document_Seq;
                        ac.Session_ID      = sessionLog.Session_ID;

                        db.Document_Access_Log.Add(ac);
                        db.SaveChanges();

                        //record action
                        global.addAudit("Repository", "Repository: Add File", "Create", User.Identity.Name);

                        //save file to server
                        model.uploadFile.SaveAs(path);
                        TempData["Message"]    = "File successfully uploaded";
                        TempData["classStyle"] = "success";
                        return(RedirectToAction("ViewFile"));
                    }
                    else
                    {
                        ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
                        ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
                        return(View());
                    }
                }
            }
            ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
            ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
            return(View());
        }
コード例 #4
0
        public ActionResult UpdateFile(UpdateFileModel model)
        {
            if (ModelState.IsValid)
            {
                //get instance of the file to be updated
                var updatedfile = db.Document_Repository.Where(f => f.Document_Seq.Equals(model.Document_Seq)).FirstOrDefault();
                //update the entries details
                updatedfile.Document_Name    = model.Document_Name;
                updatedfile.Description      = model.Description;
                updatedfile.Category_ID      = model.Category_ID;
                updatedfile.Document_Type_ID = model.Document_Type_ID;
                //check if a new file has been uploaded
                if (model.uploadFile != null)
                {
                    //get uploaded file filename
                    var filename = Path.GetFileName(model.uploadFile.FileName);
                    //get uploaded file path
                    var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), filename);
                    //determine the uploaded file extension
                    var extension = Path.GetExtension(model.uploadFile.FileName);
                    //check if the file uploaded is a valid extension
                    if (System.IO.File.Exists(path))
                    {
                        TempData["Message"]      = "Uploaded file already exists";
                        TempData["classStyle"]   = "danger";
                        model.uploadFile         = null;
                        ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
                        ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
                        return(View(model));
                    }
                    else
                    {
                        System.IO.File.Delete(updatedfile.Directory_Path);
                        model.uploadFile.SaveAs(path);
                        updatedfile.Directory_Path = path;
                    }
                }
                db.Entry(updatedfile).State = EntityState.Modified;
                db.SaveChanges();

                var sessionLog = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(p => p.Login_DateTime).FirstOrDefault();

                Document_Access_Log ac = new Document_Access_Log();
                ac.Access_DateTime = DateTime.Now;
                ac.Document_Seq    = updatedfile.Document_Seq;
                ac.Session_ID      = sessionLog.Session_ID;

                db.Document_Access_Log.Add(ac);
                db.SaveChanges();

                //record action
                global.addAudit("Repository", "Repository: Update File", "Update", User.Identity.Name);

                TempData["Message"]    = "File successfuly updated";
                TempData["classStyle"] = "success";
                return(RedirectToAction("ViewFile"));
            }
            else
            {
                ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
                ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
                return(View(model));
            }
        }