Example #1
0
 public void Dispose()
 {
     if (_db == null)
     {
         return;
     }
     _db.Dispose();
     _db = null;
 }
Example #2
0
        // GET api/people/5
        public Data.DTOs.Policy GetPolicy(int id)
        {
            Data.DTOs.Policy policy;

            using (var ctx = new ContosoInsuranceContext(_connectionString))
            {
                policy = PolicyMapping.MapEntityToDto(ctx.Policies.FirstOrDefault(p => p.Id == id));
            }

            return(policy);
        }
Example #3
0
        public Contoso.Apps.Insurance.Data.DTOs.Dependent GetDependent(int id)
        {
            Contoso.Apps.Insurance.Data.DTOs.Dependent dependent;

            using (var ctx = new ContosoInsuranceContext())
            {
                dependent = DependentMapping.MapEntityToDto(ctx.Dependents.FirstOrDefault(p => p.Id == id));
            }

            return(dependent);
        }
Example #4
0
        // GET api/policies
        public IList <Data.DTOs.Policy> GetPolicies()
        {
            List <Data.DTOs.Policy> policies;

            using (var ctx = new ContosoInsuranceContext(_connectionString))
            {
                policies = ctx.Policies.ToList().Select(PolicyMapping.MapEntityToDto).ToList();
            }

            return(policies);
        }
Example #5
0
        public Contoso.Apps.Insurance.Data.DTOs.Person GetPerson(int id)
        {
            Contoso.Apps.Insurance.Data.DTOs.Person person;

            using (var ctx = new ContosoInsuranceContext())
            {
                person = PersonMapping.MapEntityToDto(ctx.People.FirstOrDefault(p => p.Id == id));
            }

            return(person);
        }
Example #6
0
        public IList <Contoso.Apps.Insurance.Data.DTOs.Person> GetAllPeople()
        {
            List <Contoso.Apps.Insurance.Data.DTOs.Person> people;

            using (var ctx = new ContosoInsuranceContext())
            {
                people = ctx.People.OrderBy(p => p.LName).ToList().Select(PersonMapping.MapEntityToDto).ToList();
            }

            return(people);
        }
Example #7
0
        // GET api/people/5
        public Data.DTOs.Person GetPerson(int id)
        {
            Data.DTOs.Person person;

            using (var ctx = new ContosoInsuranceContext(_connectionString))
            {
                person = PersonMapping.MapEntityToDto(ctx.People.FirstOrDefault(p => p.Id == id));
            }

            return(person);
        }
        // GET api/dependents/5
        public Dependent GetDependent(int id)
        {
            Dependent dependent;

            // TODO: Review
            using (var ctx = new ContosoInsuranceContext(_connectionString))
            {
                dependent = DependentMapping.MapEntityToDto(ctx.Dependents.FirstOrDefault(p => p.Id == id));
            }

            return(dependent);
        }
Example #9
0
        public IList <Contoso.Apps.Insurance.Data.DTOs.PolicyHolder> GetPolicyHolders()
        {
            List <PolicyHolder> policies;

            using (var ctx = new ContosoInsuranceContext())
            {
                var policyHolders = ctx.PolicyHolders.Include(p => p.Policy).Include(p => p.Person)
                                    .Include(p => p.Dependents).OrderBy(p => p.Person.LName).ToList();
                policies = policyHolders.Select(PolicyHolderMapping.MapEntityToDto).ToList();
            }

            return(policies);
        }
Example #10
0
        public PolicyHolder GetPolicyHolder(int id)
        {
            PolicyHolder policyHolder;

            using (var ctx = new ContosoInsuranceContext())
            {
                var policyHolderData = ctx.PolicyHolders.Include(p => p.Policy)
                                       .Include(p => p.Person).Include(p => p.Dependents).FirstOrDefault(p => p.Id == id);
                policyHolder = PolicyHolderMapping.MapEntityToDto(policyHolderData);
            }

            return(policyHolder);
        }
Example #11
0
        // GET api/policyholders
        public IList<PolicyHolderViewModel> GetPolicyHolders()
        {
            List<PolicyHolderViewModel> policies;

            using (var ctx = new ContosoInsuranceContext(_connectionString))
            {
                var policyHolders = ctx.PolicyHolders.Include(p => p.Policy).Include(p => p.Person)
                    .Include(p => p.Dependents).OrderBy(p => p.Person.LName).ToList();
                policies = policyHolders.Select(PolicyHolderMapping.MapEntityToViewModel).ToList();
            }

            return policies;
        }
Example #12
0
 public DependentActions(string connectionString = null)
 {
     // TODO: Review
     _db = !string.IsNullOrWhiteSpace(connectionString) ? new ContosoInsuranceContext(connectionString) : new ContosoInsuranceContext();
 }