public ActionResult Delete(Category toDel)
        {
            var repo = new CategoryDatabase();
            repo.Delete(toDel.Id.ToString());

            return RedirectToAction("Index");
        }
        public bool ExsistingCategory(Category toCheck)
        {
            var currentList = GetAll();

            foreach (var c in currentList)
            {
                if (c.CategoryName == toCheck.CategoryName)
                    return true;
            }

            return false;
        }
        public ActionResult Add(Category toAdd)
        {
            var repo = new CategoryDatabase();

            if (ModelState.IsValid)
            {
                repo.Add(toAdd);
                return RedirectToAction("Index");
            }

            return View();
        }
        public List<Category> GetAll()
        {
            var reader = File.ReadAllLines(_filepath);
            var list = new List<Category>();

            for (int i = 0; i < reader.Length; i++)
            {
                var category = new Category();
                var columns = reader[i].Split('^');

                category.Id = Int32.Parse(columns[0]);
                category.CategoryName = columns[1];

                list.Add(category);
            }
            return list;
        }
        public List<Category> GetAllCategories(string filePath)
        {
            List<Category> policyCategories = new List<Category>();
            var reader = File.ReadAllLines(filePath);

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

                Category newCategory = new Category();

                newCategory.CategoryName = columns[2];
                newCategory.CategoryID = int.Parse(columns[4]);

                if (policyCategories.All(r => r.CategoryName != columns[2]))
                {
                    policyCategories.Add(newCategory);

                }
            }
            return policyCategories;
        }
        public void Add(Category add)
        {
            var list = GetAll();

            if (list.Any())
            {
                add.Id = list.Max(c => c.Id) + 1;
            }
            else
            {
                add.Id = 1;
            }
            list.Add(add);

            using (var writer = File.CreateText(_filepath))
            {
                foreach (var l in list)
                {
                    writer.WriteLine("{0}^{1}", l.Id, l.CategoryName);
                }
            }
        }
示例#7
0
 public PolicyDocument()
 {
     Category = new Category();
 }
        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;
        }