コード例 #1
0
        public HttpResponseMessage UpdateContract(ContractModel model)
        {
            using (var entities = new TakeHomeEntities())
            {
                var getContract = entities.Contracts.Where(c => c.CustomerID == model.CustomerID).FirstOrDefault();

                if (null == getContract)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                var contract = new Contract()
                {
                    Address      = model.Address,
                    Country      = model.Country,
                    CoveragePlan = model.CoveragePlan,
                    CustomerName = model.CustomerName,
                    DOB          = model.DOB,
                    Gender       = model.Gender,
                    NetPrice     = model.NetPrice,
                    SaleDate     = model.SaleDate
                };

                entities.Contracts.Add(contract);
                entities.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }
コード例 #2
0
        public static void CreateContractPlans(ContractModel contract)
        {
            var age = CalculateAge(contract.DOB);

            using (var plans = new TakeHomeEntities())
            {
                var coveragePlan = plans.CoveragePlans.ToList();
                var rateChart    = plans.RateCharts.ToList();

                var countryPlans = coveragePlan.Where(x =>
                                                      string.Equals(x.EligibilityCountry, contract.Country, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                var netPrice = rateChart.Where(y => string.Equals(y.CoveragePlan, countryPlans.CoveragePlan1, StringComparison.OrdinalIgnoreCase) &&
                                               string.Equals(y.Gender, contract.Gender, StringComparison.OrdinalIgnoreCase));

                var price = GetNetPrice(netPrice.ToList());

                var addContract = new Contract()
                {
                    Address      = contract.Address,
                    Country      = contract.Country,
                    CoveragePlan = countryPlans.CoveragePlan1,
                    CustomerName = contract.CustomerName,
                    DOB          = contract.DOB,
                    Gender       = contract.Gender,
                    NetPrice     = price,
                    SaleDate     = contract.SaleDate
                };

                plans.Contracts.Add(addContract);
                plans.SaveChanges();
            }
        }
コード例 #3
0
        public HttpResponseMessage DeleteContract(int contractId)
        {
            using (var entities = new TakeHomeEntities())
            {
                var contract = entities.Contracts.Where(c => c.CustomerID == contractId).FirstOrDefault();

                entities.Entry(contract).State = System.Data.Entity.EntityState.Deleted;
                entities.SaveChanges();

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
        }