public void PolicyLoader()
        {
            PolicyDBConnect policyDBConnect = new PolicyDBConnect();
            var             v = from p in policyDBConnect.Policies
                                select p;

            if (v.ToList().Count > 0)
            {
                return;
            }


            Policy[] policies = new Policy[]
            {
                new Policy {
                    Id = 1, Copay = 20, Deductible = 40, Name = "Standard", Rate = 250, Type = "Medical"
                },
                new Policy {
                    Id = 2, Copay = 40, Deductible = 60, Name = "Excellent", Rate = 300, Type = "Medical"
                },
                new Policy {
                    Id = 3, Copay = 50, Deductible = 80, Name = "Best", Rate = 350, Type = "Medical"
                }
            };
            policyDBConnect.Policies.AddRange(policies);
            policyDBConnect.SaveChanges();
        }
        public HttpResponseMessage UpdatePolicy([FromBody] Policy policy)
        {
            // Update Policy
            PolicyDBConnect policyDBConnect = new PolicyDBConnect();
            Policy          pi  = null;
            var             pol = from p in policyDBConnect.Policies
                                  where p.Id == policy.Id
                                  select p;

            foreach (var item in pol)
            {
                item.Name       = policy.Name;
                item.Rate       = policy.Rate;
                item.Deductible = policy.Deductible;
                item.Copay      = policy.Copay;
            }
            policyDBConnect.SaveChanges();

            string output = JsonConvert.SerializeObject(pi);

            return(new HttpResponseMessage()
            {
                Content = new StringContent(output, Encoding.UTF8, "application/json"),
                StatusCode = HttpStatusCode.Created
            });
        }
Beispiel #3
0
        public ActionResult AddPolicy(Policy policy)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            PolicyDBConnect context = new PolicyDBConnect();

            context.Policies.Add(policy);
            context.SaveChanges();
            ViewBag.Message = "Policy " + policy.PolicyName + " added.";

            return(View());
        }
        public HttpResponseMessage AddPolcy([FromBody] Policy policy)
        {
            // Add Policy
            PolicyDBConnect policyDBConnect = new PolicyDBConnect();

            policyDBConnect.Policies.Add(policy);
            policyDBConnect.SaveChanges();

            string output = JsonConvert.SerializeObject(policy);

            return(new HttpResponseMessage()
            {
                Content = new StringContent(output, Encoding.UTF8, "application/json"),
                StatusCode = HttpStatusCode.Created
            });
        }
Beispiel #5
0
        public void SetUpPolicies()
        {
            //  not best practice but for demo purposes.
            PolicyDBConnect context = new PolicyDBConnect();

            Policy[] array = new Policy[]
            {
                new Policy {
                    PolicyID = 1, Copay = 200, Deductible = 500, PolicyName = "Standard", Rate = 250, PolicyType = "Medical"
                },
                new Policy {
                    PolicyID = 2, Copay = 20, Deductible = 100, PolicyName = "Excellent", Rate = 150, PolicyType = "Medical"
                }
            };
            context.Policies.AddRange(array);
            context.SaveChanges();
        }