Esempio n. 1
0
        public HttpResponseMessage ListAllPolicies()
        {
            PolicyLoader();

            List <Policy> policyList = new List <Policy>();

            PolicyDBConnect policyDBConnect = new PolicyDBConnect();
            var             pol             = from p in policyDBConnect.Policies
                                              select p;

            foreach (var item in pol)
            {
                policyList.Add(item);
            }

            if (policyList.Count > 0)
            {
                string output = JsonConvert.SerializeObject(policyList);
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(output, Encoding.UTF8, "application/json"),
                    StatusCode = HttpStatusCode.Created
                });
            }
            else
            {
                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.NotFound
                });
            }
        }
Esempio n. 2
0
        public HttpResponseMessage ReadPolicy(int id)
        {
            // Read Policy
            PolicyDBConnect policyDBConnect = new PolicyDBConnect();
            var             pol             = from p in policyDBConnect.Policies
                                              where p.Id == id
                                              select p;
            Policy po = new Policy();

            foreach (var p in pol)
            {
                po.Id         = p.Id;
                po.Copay      = p.Copay;
                po.Deductible = p.Deductible;
                po.Rate       = p.Rate;
                po.Type       = p.Type;
                po.Name       = p.Name;
            }
            if (po != null)
            {
                string output = JsonConvert.SerializeObject(po);
                return(new HttpResponseMessage()
                {
                    Content = new StringContent(output, Encoding.UTF8, "application/json"),
                    StatusCode = HttpStatusCode.Created
                });
            }
            else
            {
                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.NotFound
                });
            }
        }
Esempio n. 3
0
        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
            });
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        public ActionResult PolicySearch(PolicySearch policysearch)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            PolicyDBConnect context = new PolicyDBConnect();
            bool            all     = (policysearch.PolicyName == null) ? true : false;

            if (all)
            {
                var pol = from p in context.Policies
                          select p;
                policysearch.policies = pol.ToList();
            }
            else
            {
                var pol = from p in context.Policies
                          where p.PolicyName.StartsWith(policysearch.PolicyName)
                          select p;
                policysearch.policies = pol.ToList();
            }

            return(View(policysearch));
        }
Esempio n. 6
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());
        }
Esempio n. 7
0
        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
            });
        }
Esempio n. 8
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();
        }
Esempio n. 9
0
        public List <SelectListItem> UtilityPolicySearch()
        {
            // produces item list of policies in system
            // used in assign policy screen and policy search screens.

            List <SelectListItem> a = new List <SelectListItem>();

            PolicyDBConnect context = new PolicyDBConnect();
            var             list    = from p in context.Policies
                                      select p;

            foreach (var p in list)
            {
                SelectListItem b = new SelectListItem();
                b.Text  = p.PolicyName;
                b.Value = p.PolicyID.ToString();
                a.Add(b);
            }
            return(a);
        }