public List<Policy> GetAll()
        {
            List<Policy> AllPolicies = new List<Policy>();

            if (File.Exists(_fileName))
            {
                var reader = File.ReadAllLines(_fileName);

                // read the header

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

                    for (int j = 2; j < columns.Count() - 1; j++)
                    {
                        policy.PolicyDescription += columns[j] + ",";
                    }
                    policy.PolicyDescription = policy.PolicyDescription.TrimEnd(',');

                    policy.PolicyID = int.Parse(columns[0]);
                    policy.PolicyName = columns[1];
                    //policy.PolicyDescription = columns[columns.Count() - 2];
                    policy.Category = columns[columns.Count() - 1];

                    AllPolicies.Add(policy);
                }

            }

            return AllPolicies;
        }
 public void Edit(Policy policy)
 {
     var policyList = GetAll();
     policyList.RemoveAll(p => p.PolicyID == policy.PolicyID);
     policyList.Add(policy);
     WriteFile(policyList);
 }
        public void Add(Policy newPolicy)
        {
            // ternary operator is saying:
            // if there are any contacts return the max contact id and add 1 to set our new contact id
            // else set to 1
            newPolicy.PolicyID = (GetAll().Any()) ? GetAll().Max(p => p.PolicyID) + 1 : 1;

            var Policies = GetAll();
            Policies.Add(newPolicy);

            WriteFile(Policies);
        }
        public ActionResult EditPolicy(int id)
        {
            Policy policy = new Policy();
            policy.PolicyID = int.Parse(Request.Form["id"]);
            policy.PolicyName = Request.Form["Name"];
            policy.PolicyDescription = Request.Form["Description"];
            policy.Category = Request.Form["Category"];

            var repo = new PolicyRepository();
            repo.RootPath = Server.MapPath("~/");
            repo.Edit(policy);

            return RedirectToAction("Manage");
        }
        public ActionResult AddPolicy()
        {
            var p = new Policy();

            p.PolicyName = Request.Form["Name"];
            p.PolicyDescription = Request.Form["Description"];
            p.Category = Request.Form["Category"];

            var repo = new PolicyRepository();
            repo.RootPath = Server.MapPath("~/");
            repo.Add(p);

            return RedirectToAction("Manage");
        }