コード例 #1
0
        public void AddPolicyDocument(string filePath, PolicyDocument document)
        {
            var policyList = GetAllPolicyDocuments(filePath);
            if (document.Category.CategoryID == 0)
            {
                int categoryID = policyList.Max(m => m.Category.CategoryID) + 1;
                document.Category.CategoryID = categoryID;

            }
            int newPolicyId = policyList.Max(m=> m.PolicyDocumentId)+1;
            document.PolicyDocumentId = newPolicyId;

            var existingCategory = GetAllCategories(filePath).FirstOrDefault(s => s.CategoryID == document.Category.CategoryID);
            document.Category.CategoryName = existingCategory.CategoryName;
            policyList.Add(document);
            OverwriteFile(policyList,filePath);
        }
コード例 #2
0
        public ActionResult AddPolicyDocument(UploadPolicyVM model)
        {
            var fullPath = Server.MapPath(@"~/PolicyDocuments/PolicyDocuments.txt");
            var ops = FileManager.CreatePolicyDocumentOperations();

            if (ModelState.IsValid)
            {
                var file = model.file;
                if (file.ContentLength > 0)
                {
                    var directoryPath = Server.MapPath(@"~/PolicyDocuments");
                    file.SaveAs(String.Format(@"{0}\{1}", directoryPath, file.FileName));

                    var policyDoc = new PolicyDocument();

                    string extension = Path.GetExtension(file.FileName);
                    //null ref - needs to be updated

                    if (!model.NewCategory.IsEmpty())
                    {
                        policyDoc.Category.CategoryName = model.NewCategory.ToUpper();
                    }

                    else
                    {
                        policyDoc.Category.CategoryID = model.SelectedCategory;
                    }

                    policyDoc.Name = model.DocName;

                    policyDoc.FilePath = file.FileName;

                    ops.AddPolicyDocument(policyDoc, fullPath);
                    return View("ConfirmationPage");
                }
            }

            var response = ops.GetAllCategories(fullPath);
            model.CreateCategoryList(response.Data);

            return View(model);
        }
コード例 #3
0
        public List<PolicyDocument> GetAllPolicyDocuments(string filePath)
        {
            List<PolicyDocument> policyDocuments = new List<PolicyDocument>();

            var reader = File.ReadAllLines(filePath);

            for (int i = 1; i < reader.Length; i++)
            {
                var columns = reader[i].Split(',');

                var policyDoc = new PolicyDocument();

                policyDoc.PolicyDocumentId = int.Parse(columns[0]);
                policyDoc.Name = columns[1];
                policyDoc.Category.CategoryName = columns[2];
                policyDoc.FilePath = columns[3];

                    policyDocuments.Add(policyDoc);

            }

            return policyDocuments;
        }
コード例 #4
0
 public void AddPolicyDocument(PolicyDocument policyDocument, string folderPath)
 {
     var repo = new PolicyDocumentRepository();
     repo.AddNewPolicyDocument(policyDocument, folderPath);
     List<Category> categories = repo.GetAllPolicyDocCategories(folderPath);
 }
コード例 #5
0
 public void DeletePolicyDocument(string filePath, PolicyDocument policyDoc)
 {
     var repo = new PolicyDocumentRepository();
     repo.DeletePolicyDocument(filePath, policyDoc);
 }
コード例 #6
0
 public void AddPolicyDocument(PolicyDocument document, string filePath)
 {
     var repo = new PolicyDocumentRepository();
     repo.AddPolicyDocument(filePath,document);
 }
コード例 #7
0
        public List<PolicyDocument> GetPolicyDocumentsByCategory(string directoryPath, int category)
        {
            var filePath = directoryPath + "PolicyDocuments.txt";

            List<PolicyDocument> policyDocuments = new List<PolicyDocument>();

            var reader = File.ReadAllLines(filePath);

            for (int i = 1; i < reader.Length; i++)
            {
                var columns = reader[i].Split(',');

                var policyDoc = new PolicyDocument();
                var policyDocCat = new Category();
                policyDoc.PolicyDocumentId = int.Parse(columns[0]);
                policyDoc.Name = columns[1];
                policyDocCat.CategoryName = columns[2];
                var filePathEnd = columns[3];
                policyDocCat.CategoryID = int.Parse(columns[4]);
                policyDoc.Category = policyDocCat;

                policyDoc.FilePath = directoryPath + filePathEnd;

                if(policyDoc.Category.CategoryID == category)
                {
                policyDocuments.Add(policyDoc);
                }

            }

            return policyDocuments;
        }
コード例 #8
0
 public void DeletePolicyDocument(string filePath, PolicyDocument document)
 {
     var policyList = GetAllPolicyDocuments(filePath);
     policyList.Remove(document);
     OverwriteFile(policyList, filePath);
 }