Exemple #1
0
        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);
        }
Exemple #2
0
        public IActionResult CalculateTotalPrice([FromBody] PriceEstimationModel priceEstimationModel)
        {
            if (ModelState.IsValid)
            {
                var totalPrice = this.GetTotalPrice(priceEstimationModel);
                return(Ok(new { TotalPrice = totalPrice }));
            }

            return(BadRequest());
        }
Exemple #3
0
        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());
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        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());
        }
Exemple #6
0
        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);
        }
Exemple #7
0
 private decimal GetTotalPrice(PriceEstimationModel priceEstimationModel)
 {
     eligibleForDiscount = Convert.ToBoolean(HttpContext.User.Claims.FirstOrDefault(x => x.Type == Constants.PrivilegedUserClaim)?.Value);
     return(_goldPriceEstimation.CalculateTotalPrice(priceEstimationModel, eligibleForDiscount));
 }