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); }
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; }
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; }
public ActionResult PolicyView(Policy policy) { var manager = new PolicyManager(); var response = manager.GetPolicy(policy); return View(response.Data); }
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); }
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"); }
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; }
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); } } } }
public void AddNewPolicyInExistingCategory(Policy newPolicy) { ListOfPolicies.Add(newPolicy); }
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; }
public Policy AddNewPolicy(Policy newPolicy) { throw new NotImplementedException(); }
public void AddPolicy(Policy newpolicy) { _policies.Add(newpolicy); }
//Add a new policy into an existing category public void AddNewPolicyInExistingCat(Policy newPolicy) { _repo.AddNewPolicyInExistingCategory(newPolicy); }
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; }
public void AddNewPolicyInNewCategory(Policy newPolicy) { ListOfPolicies.Add(newPolicy); PolicyCategory newCategory = new PolicyCategory() { CategoryTitle = newPolicy.Category.CategoryTitle }; ListOfPolicyCategories.Add(newCategory); }
public void AddNewPolicyInNewCategory(Policy newPolicy) { throw new NotImplementedException(); }
//Add new policy (sql) public Policy AddNewPolicy(Policy newPolicy) { return _repo.AddNewPolicy(newPolicy); }
public CreatePolicyVM() { Policy = new Policy(); PolCatsList = new List<SelectListItem>(); }
//Add a new policy into a new category public void AddNewPolicyInNewCat(Policy newPolicy) { _repo.AddNewPolicyInNewCategory(newPolicy); }
public CreatePolicyVM(List<PolicyCategory> catsList) { Policy = new Policy(); PolCatsList = new List<SelectListItem>(); CreatePolicyCatList(catsList); }
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); } }
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; }
public void AddPolicy(Policy newPolicy) { newPolicy.ID = _policies.Max(p => p.ID) + 1; _policies.Add(newPolicy); AddCategory(newPolicy.Category); WritePolicyToFile(newPolicy); }
public PolicyToAddVM() { PolicyToAdd = new Policy(); CategoryList = new List<SelectListItem>(); CreateCategoryList(); }