private PriceEstimationModel GetNearestSoldModel(PriceEstimationModel modelA, PriceEstimationModel modelB, int rent) { var priceDiffA = Math.Abs(rent - (int)modelA.Rent); var priceDiffB = Math.Abs(rent - (int)modelB.Rent); return(priceDiffA < priceDiffB ? modelA : modelB); }
public IActionResult CalculateTotalPrice([FromBody] PriceEstimationModel priceEstimationModel) { if (ModelState.IsValid) { var totalPrice = this.GetTotalPrice(priceEstimationModel); return(Ok(new { TotalPrice = totalPrice })); } return(BadRequest()); }
public IActionResult PrintToScreen([FromBody] PriceEstimationModel priceEstimationModel) { if (ModelState.IsValid) { var totalPrice = this.GetTotalPrice(priceEstimationModel); var calculatedPriceModel = this.GetCalculatedPriceModel(priceEstimationModel, totalPrice); return(Ok(calculatedPriceModel)); } return(BadRequest()); }
public decimal CalculateTotalPrice(PriceEstimationModel priceEstimationModel, bool eligibleForDiscount) { if (!eligibleForDiscount) { priceEstimationModel.Discount = null; } var totalPrice = priceEstimationModel.GoldPrice * priceEstimationModel.Weight; var netPrice = priceEstimationModel.Discount != null && priceEstimationModel.Discount.Value > 0 ? totalPrice - ((priceEstimationModel.Discount / 100) * totalPrice) : totalPrice; return(netPrice.Value); }
public IActionResult PrintToPaper([FromBody] PriceEstimationModel priceEstimationModel) { if (ModelState.IsValid) { var totalPrice = this.GetTotalPrice(priceEstimationModel); var calculatedPriceModel = this.GetCalculatedPriceModel(priceEstimationModel, totalPrice); var printService = _serviceResolver(PrintOptions.PrintToPaper); printService.Print(calculatedPriceModel); return(Ok()); } return(BadRequest()); }
private CalculatedPriceModel GetCalculatedPriceModel(PriceEstimationModel priceEstimationModel, decimal totalPrice) { CalculatedPriceModel calculatedPriceModel = null; if (priceEstimationModel != null) { calculatedPriceModel = new CalculatedPriceModel { GoldPrice = priceEstimationModel.GoldPrice, Weight = priceEstimationModel.Weight, Discount = eligibleForDiscount ? priceEstimationModel.Discount : null, TotalPrice = totalPrice }; } return(calculatedPriceModel); }
private decimal GetTotalPrice(PriceEstimationModel priceEstimationModel) { eligibleForDiscount = Convert.ToBoolean(HttpContext.User.Claims.FirstOrDefault(x => x.Type == Constants.PrivilegedUserClaim)?.Value); return(_goldPriceEstimation.CalculateTotalPrice(priceEstimationModel, eligibleForDiscount)); }