public static async Task <Benefits> UpdateCosts(BenefitsCost benefitsCost) { using (var context = new DbModel <Benefits>()) { var benef = context.First(); benef.Cost.Employee = benefitsCost.Employee; benef.Cost.Dependent = benefitsCost.Dependent; benef.Cost.Description = benefitsCost.Description; return(await context.Update(benef)); } }
private BenefitsCost GetBenefitsCost() { var cost = new BenefitsCost(); cost.GrossSalaryPerPayCheck = 2000; cost.BenefitsCostPerPayCheck = 100; cost.NetSalaryPerPayCheck = 1900; cost.OtherDeductionsPerPayCheck = 0; cost.NumberOfPayChecksPerYear = 26; return(cost); }
/// <summary> /// Updates the existing benefits costs /// </summary> /// <param name="benefitsCost">The new benefits </param> /// <returns>Return Status code 200 OK on success</returns> public async Task <IHttpActionResult> Post([FromBody] BenefitsCost benefitsCost) { try { await Data.UpdateCosts(benefitsCost); return(Ok(Get(true))); } catch (Exception e) { logger.Error(e); return(InternalServerError(e)); } }
/// <summary> /// Get the yearly cost of benefits /// </summary> /// <param name="bypassCache">Option to bypass the cache (default = false)</param> /// <returns>Returns the yearly cost of benefits for employees and dependents</returns> public BenefitsCost Get(bool bypassCache = false) { var response = new BenefitsCost(); try { response = Data.Costs(bypassCache); } catch (Exception e) { logger.Error(e); } return(response); }
public void ItShouldReturnTheBenefits() { var employee = Builder <Employee> .CreateNew().Build(); var benefitsCost = Mapper.Map <BenefitsCost>(employee); var expectedCost = new BenefitsCost { EmployeeId = employee.Id, EmployeeName = employee.Name, NumberOfDependents = employee.NumberOfDependents, CostOfBenefits = 1500m, }; benefitsCost.ShouldBeEquivalentTo(expectedCost); }
public BenefitsCost CalculateBenefitsCost(Employee employee) { decimal yearlyBenefitCostForEmployee = _benefitsRepository.GetYearlyBenefitsCostForEmployee(); decimal yearlyBenefitCostForSpouse = _benefitsRepository.GetYearlyBenefitsCostForSpouse(); decimal yearlyBenefitsCostForDependent = _benefitsRepository.GetYearlyBenefitsCostForDependent(); int numberOfPayChecksPerYear = 26; decimal otherDeductions = _employeeRepository.GetOtherDeducsiontsForEmployee(employee); decimal grossSalaryPerPayCheck = _employeeRepository.GetPerPaychheckGrossSalaryForEmployee(employee); decimal discountedYearlyBenefitsCostForEmployee = getDiscountedPersonCost(yearlyBenefitCostForEmployee, employee); decimal totalYearlyCostForBenefits = discountedYearlyBenefitsCostForEmployee; if (employee.Spouse != null && !String.IsNullOrWhiteSpace(employee.Spouse?.Name)) { totalYearlyCostForBenefits += getDiscountedPersonCost(yearlyBenefitCostForSpouse, employee.Spouse); } if (employee.Dependents != null && employee.Dependents?.Count > 0) { employee.Dependents.ForEach(d => { totalYearlyCostForBenefits += getDiscountedPersonCost(yearlyBenefitsCostForDependent, d); }); } decimal costPerPayCheckForEmployee = Math.Round(totalYearlyCostForBenefits / numberOfPayChecksPerYear, 2); var netSalaryPerPayCheck = grossSalaryPerPayCheck - costPerPayCheckForEmployee - otherDeductions; var costs = new BenefitsCost(); costs.BenefitsCostPerPayCheck = costPerPayCheckForEmployee; costs.OtherDeductionsPerPayCheck = otherDeductions; costs.GrossSalaryPerPayCheck = grossSalaryPerPayCheck; costs.NetSalaryPerPayCheck = netSalaryPerPayCheck; costs.NumberOfPayChecksPerYear = numberOfPayChecksPerYear; return(costs); }
public static BenefitsCost Costs(bool bypassCache) { var response = new BenefitsCost(); var memCache = MemoryCache.Default.Get(Constants.Cache.BENEFITS_COST); if ((bypassCache) || (memCache == null)) { using (var context = new DbModel <BenefitsCost>()) { response = context.First(); } var policy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromHours(1) }; MemoryCache.Default.Add(Constants.Cache.BENEFITS_COST, response, policy); } else { response = (BenefitsCost)memCache; } return(response); }
/// <summary> /// Constructor /// </summary> /// <param name="Cost">Cost of benefits</param> /// <param name="Discounts">List of Benefits Discount</param> public Benefits(BenefitsCost Cost, List <BenefitsDiscount> Discounts) { cost = Cost; discounts = Discounts; }