예제 #1
0
        public Response<Policy> GetPolicies(Policy p)
        {
            var response = new Response<Policy>();

            try
            {
                var policy = _repo.LoadPolicies(p);

                if (policy == null)
                {
                    response.Success = false;
                    response.Message = "Policy was not found...";
                }
                else
                {
                    response.Success = true;
                    response.Data = policy;
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
        public ActionResult DeletePolicy(Policy policy)
        {
            var manager = new PolicyManager();
            var response = manager.DeletePolicy(policy);

            return View("DeletePolicy", response.Data);
        }
예제 #3
0
        public Policy AddNewPolicy(Policy newPolicy)
        {
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = cn;
                cn.Open();
                //if new category, check to see if category exists via search then add it

                //Add Policy in existing category
                var p = new DynamicParameters();
                p.Add("PolicyTitle", newPolicy.Title);
                p.Add("CategoryID", newPolicy.Category.CategoryId);
                p.Add("DateCreated", newPolicy.DateCreated);
                p.Add("ContentText", newPolicy.ContentText);
                p.Add("PolicyID", DbType.Int32, direction: ParameterDirection.Output);

                cn.Execute("AddNewPolicy", p, commandType: CommandType.StoredProcedure);

                newPolicy.PolicyId = p.Get<int>("PolicyID");

                var p1 = new DynamicParameters();
                p1.Add("CategoryID", newPolicy.Category.CategoryId);
                var category =
                    cn.Query<PolicyCategory>("SELECT * FROM Categories WHERE CategoryID = @CategoryID", p1)
                        .FirstOrDefault();
                if (category != null)
                {
                   newPolicy.Category.CategoryTitle = category.CategoryTitle;
                }

            }
            return newPolicy;
        }
예제 #4
0
        public Response<Policy> CreatePolicy(Policy newPolicy)
        {
            var response = new Response<Policy>();

            try
            {
                var allPolicies = _repo.GetAllPolicies(newPolicy);

                int LatestPolicyNumber = allPolicies.Select(a => a.PolicyID).LastOrDefault();
                newPolicy.PolicyID = LatestPolicyNumber + 1;

                response.Data = new Policy();
                response.Data.Category = newPolicy.Category;
                response.Data.PolicyTitle = newPolicy.PolicyTitle;
                response.Data.PolicyDescription = newPolicy.PolicyDescription;
                response.Data.PolicyID = newPolicy.PolicyID;

                response.Success = true;
                _repo.CreatePolicy(newPolicy);
                response.Message = "Application was created.";
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
예제 #5
0
        public ActionResult PolicyView(Policy policy)
        {
            var manager = new PolicyManager();
            var response = manager.GetPolicy(policy);

            return View(response.Data);
        }
예제 #6
0
        public ActionResult Display(string category)
        {
            var policy = new Policy();
            policy.Category = category;

            var manager = new PolicyManager();
            var response = manager.LoadAllPolicies(policy);

            return View(response.Data);
        }
예제 #7
0
        public ActionResult AddPolicy(string Name, string CategorySelected, string Description)
        {
            var repo = new PolicyRepository();
            var newPolicy = new Policy();

            newPolicy.Name = Name;
            newPolicy.Category = CategorySelected;
            newPolicy.Description = Description;

            repo.AddPolicy(newPolicy);

            return View("AddSuccess");
        }
예제 #8
0
        public Response<Policy> DeletePolicy(Policy PolicyToDelete)
        {
            var response = new Response<Policy>();

            try
            {
                _repo.DeletePolicy(PolicyToDelete);

                response.Success = true;
                response.Message = "You have successfully deleted the policy";

            }
            catch(Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;

            }
            return response;
        }
예제 #9
0
        public PolicyRepository()
        {
            _policies.Clear();
            _categories.Clear();

            var categoryDirectories = Directory.GetDirectories(_filePath).ToList();

            foreach (var folder in categoryDirectories)
            {
                var files = Directory.GetFiles(folder);

                foreach (var file in files)
                {
                    var position = folder.LastIndexOf('\\');
                    if (file == folder + folder.Substring(position) + ".txt")
                    {
                        var reader = File.ReadAllLines(file);
                        _categories.Add(reader[0]);
                    }
                    else
                    {
                        Policy newPolicy = new Policy();
                        var reader = File.ReadAllLines(file);

                        newPolicy.ID = int.Parse(reader[0]);

                        newPolicy.Category = reader[1];

                        newPolicy.Name = reader[2];

                        for (int i = 3; i < reader.Length; i++)
                        {
                            newPolicy.Description = newPolicy.Description + reader[i] + "\n";
                        }

                        _policies.Add(newPolicy);
                    }
                }

            }
        }
예제 #10
0
 public void AddNewPolicyInExistingCategory(Policy newPolicy)
 {
     ListOfPolicies.Add(newPolicy);
 }
예제 #11
0
        public Response<List<Policy>> LoadAllPolicies(Policy p)
        {
            var response = new Response<List<Policy>>();

            try
            {
                response.Data = _repo.GetAllPolicies(p);
                response.Message = "Success";
                response.Success = true;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
예제 #12
0
 public Policy AddNewPolicy(Policy newPolicy)
 {
     throw new NotImplementedException();
 }
예제 #13
0
 public void AddPolicy(Policy newpolicy)
 {
     _policies.Add(newpolicy);
 }
예제 #14
0
 //Add a new policy into an existing category
 public void AddNewPolicyInExistingCat(Policy newPolicy)
 {
     _repo.AddNewPolicyInExistingCategory(newPolicy);
 }
예제 #15
0
        public List<Policy> GetAllPolicies()
        {
            using (SqlConnection cn = new SqlConnection(Settings.ConnectionString))
            {
                var cmd = new SqlCommand();
                cmd.CommandText = "select p.PolicyID, p.PolicyTitle, p.CategoryID, c.CategoryTitle, p.DateCreated, p.ContentText from [Policies] p" +
                                  " LEFT JOIN [Categories] c ON p.CategoryID = c.CategoryID";
                cmd.Connection = cn;
                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var newPolicy = new Policy();
                        newPolicy.PolicyId = int.Parse(dr["PolicyID"].ToString());
                        newPolicy.Title = dr["PolicyTitle"].ToString();
                        newPolicy.Category.CategoryId = int.Parse(dr["CategoryID"].ToString());
                        newPolicy.Category.CategoryTitle = dr["CategoryTitle"].ToString();
                        newPolicy.DateCreated = DateTime.Parse(dr["DateCreated"].ToString());
                        newPolicy.ContentText = dr["ContentText"].ToString();

                        ListOfPolicies.Add(newPolicy);
                    }
                }
            }

            return ListOfPolicies;
        }
예제 #16
0
 public void AddNewPolicyInNewCategory(Policy newPolicy)
 {
     ListOfPolicies.Add(newPolicy);
     PolicyCategory newCategory = new PolicyCategory()
     {
         CategoryTitle = newPolicy.Category.CategoryTitle
     };
     ListOfPolicyCategories.Add(newCategory);
 }
예제 #17
0
 public void AddNewPolicyInNewCategory(Policy newPolicy)
 {
     throw new NotImplementedException();
 }
예제 #18
0
 //Add new policy (sql)
 public Policy AddNewPolicy(Policy newPolicy)
 {
     return _repo.AddNewPolicy(newPolicy);
 }
예제 #19
0
 public CreatePolicyVM()
 {
     Policy = new Policy();
     PolCatsList = new List<SelectListItem>();
 }
예제 #20
0
 //Add a new policy into a new category
 public void AddNewPolicyInNewCat(Policy newPolicy)
 {
     _repo.AddNewPolicyInNewCategory(newPolicy);
 }
예제 #21
0
 public CreatePolicyVM(List<PolicyCategory> catsList)
 {
     Policy = new Policy();
     PolCatsList = new List<SelectListItem>();
     CreatePolicyCatList(catsList);
 }
예제 #22
0
        private void WritePolicyToFile(Policy newPolicy)
        {
            string policyFilePath = (_filePath + newPolicy.Category + "\\" + newPolicy.Name + ".txt").Replace(" ", String.Empty);

            if (File.Exists(policyFilePath))
             {
                File.Delete(policyFilePath);
            }

            using (var writer = File.CreateText(policyFilePath))
            {
                writer.WriteLine("{0}", newPolicy.ID);
                writer.WriteLine("{0}", newPolicy.Category);
                writer.WriteLine("{0}", newPolicy.Name);
                writer.WriteLine("{0}", newPolicy.Description);

            }
        }
예제 #23
0
        public Response<Policy> GetPolicy(Policy policy)
        {
            var response = new Response<Policy>();

            try
            {
                response.Data = _repo.GetPolicy(policy);

                response.Success = true;
                response.Message = "you have successfully gotten the policy.";
            }
            catch(Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
예제 #24
0
        public void AddPolicy(Policy newPolicy)
        {
            newPolicy.ID = _policies.Max(p => p.ID) + 1;

            _policies.Add(newPolicy);

            AddCategory(newPolicy.Category);

            WritePolicyToFile(newPolicy);
        }
예제 #25
0
 public PolicyToAddVM()
 {
     PolicyToAdd = new Policy();
     CategoryList = new List<SelectListItem>();
     CreateCategoryList();
 }