Example #1
0
        public IActionResult PutInsurance([FromRoute] int id, [FromBody] InsuranceViewModel insurance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != insurance.id)
            {
                return(BadRequest());
            }

            bool result = false;

            try
            {
                result = insuranceMap.Update(insurance);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!result)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult Index(InsuranceViewModel model)
        {
            InsuranceService service = new InsuranceService();

            ViewBag.age     = model.age;
            ViewBag.gender  = model.gender;
            ViewBag.premium = service.CalcPremium(model.age, model.gender);

            return(View());
        }
Example #3
0
        public IActionResult PostInsurance([FromBody] InsuranceViewModel insurance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            insurance = insuranceMap.Create(insurance);

            return(CreatedAtAction("GetInsurance", new { insurance.id }, insurance));
        }
Example #4
0
        private static Insurance MapInsurance(InsuranceViewModel insuranceViewModel)
        {
            if (insuranceViewModel == null)
            {
                return(null);
            }

            return(new Insurance
            {
                InsuranceName = insuranceViewModel.InsuranceName
            });
        }
Example #5
0
        private Insurance ViewModelToDomain(InsuranceViewModel officeViewModel)
        {
            Insurance domain = new Insurance();

            domain.Id           = officeViewModel.id;
            domain.Name         = officeViewModel.name;
            domain.Description  = officeViewModel.description;
            domain.Covering     = officeViewModel.covering;
            domain.ValidFrom    = officeViewModel.validFrom;
            domain.CoverageTime = officeViewModel.coverageTime;
            domain.Price        = officeViewModel.price;
            domain.RiskLevel    = officeViewModel.riskLevel;

            return(domain);
        }
        public ActionResult AddInsurance(InsuranceViewModel model)
        {
            var selectedInsuranceType = _insuranceTypeRepository.GetPolis(model.InsuranceNameType, model.InsurancePeriod);
            var user = _userService.GetCurrent();

            var newInsurance = new Insurance()
            {
                InsuranceType   = selectedInsuranceType,
                DateCreationing = DateTime.Now,
                Owner           = user
            };

            _insuranceRepository.Save(newInsurance);

            return(RedirectToAction("Insurance"));
        }
Example #7
0
        public static InsuranceListViewModel GetInsuranceByUser(string username)
        {
            Entities entities   = new Entities();
            var      insurances = entities.Assets.Include("Expenses").Where(x => x.Username.Equals(username) &&
                                                                            x.AssetType == (int)Constants.Constants.ASSET_TYPE.INSURANCE &&
                                                                            !x.DisabledDate.HasValue).OrderBy(x => x.AssetName).ToList();
            InsuranceListViewModel result = new InsuranceListViewModel();

            foreach (var insurance in insurances)
            {
                var expense = insurance.Expenses1.FirstOrDefault();
                InsuranceViewModel viewModel = new InsuranceViewModel
                {
                    Id            = insurance.Id,
                    Name          = insurance.AssetName,
                    Value         = insurance.Value,
                    StartDate     = insurance.StartDate.Value,
                    EndDate       = insurance.EndDate.Value,
                    PaymentPeriod = Helper.TimePeriodString(insurance.StartDate.Value, insurance.EndDate.Value),
                    Expense       = expense.Value,
                    AnnualExpense = expense.Value * 12,
                    Note          = insurance.Note
                };

                int paymentPeriod = Helper.CalculateTimePeriod(insurance.StartDate.Value, insurance.EndDate.Value);
                viewModel.TotalExpense = paymentPeriod * viewModel.Expense;
                viewModel.YieldRate    = viewModel.TotalExpense > 0 ? (viewModel.Value - viewModel.TotalExpense) / viewModel.TotalExpense : 0;
                int currentPeriod = Helper.CalculateTimePeriod(viewModel.StartDate, DateTime.Now);
                viewModel.RemainedValue = viewModel.TotalExpense - viewModel.Expense * currentPeriod;

                result.Insurances.Add(viewModel);
            }

            result.TotalValue         = result.Insurances.Sum(x => x.Value);
            result.TotalTotalExpense  = result.Insurances.Sum(x => x.TotalExpense);
            result.TotalExpense       = result.Insurances.Sum(x => x.Expense);
            result.TotalAnnualExpense = result.Insurances.Sum(x => x.AnnualExpense);
            result.TotalRemainedValue = result.Insurances.Sum(x => x.RemainedValue);
            result.IsInitialized      = UserQueries.IsCompleteInitialized(username);

            return(result);
        }
Example #8
0
        private InsuranceViewModel DomainToViewModel(Insurance domain)
        {
            if (domain != null)
            {
                InsuranceViewModel model = new InsuranceViewModel();
                model.id           = domain.Id;
                model.name         = domain.Name;
                model.description  = domain.Description;
                model.covering     = domain.Covering;
                model.validFrom    = domain.ValidFrom;
                model.coverageTime = domain.CoverageTime;
                model.price        = domain.Price;
                model.riskLevel    = domain.RiskLevel;

                return(model);
            }
            else
            {
                return(null);
            }
        }
 public IHttpActionResult UpdateInsurance(InsuranceViewModel model)
 {
     _adminService.UpdateInsurance(model.ToServiceRequestModel());
     return(Ok());
 }
Example #10
0
        public async Task <IHttpActionResult> InsuranceUpdate(InsuranceViewModel model)
        {
            await WebApiService.Instance.PostAsync("admin/insurance/update", model);

            return(Ok());
        }
 public InsuranceView(InsuranceViewModel viewmodel)
 {
     DataContext = viewmodel;
     InitializeComponent();
 }
Example #12
0
 internal InsurancePage(InsuranceViewModel ivm) : this()
 {
     BindingContext = ivm;
 }
Example #13
0
        public bool Update(InsuranceViewModel viewModel)
        {
            Insurance insurance = ViewModelToDomain(viewModel);

            return(insuranceService.Update(insurance));
        }
Example #14
0
        public InsuranceViewModel Create(InsuranceViewModel viewModel)
        {
            Insurance insurance = ViewModelToDomain(viewModel);

            return(DomainToViewModel(insuranceService.Create(insurance)));
        }
 public InsurancePage()
 {
     page        = this;
     DataContext = new InsuranceViewModel();
     InitializeComponent();
 }