public double CalculateDiscount()
        {
            double orderDiscount = 0;
            OrderAmountDiscountCriteria criteria = this.criteria.GetOrderAmountDiscountByTotalAmount(this.totalOrderAmount);

            if (criteria != null)
            {
                orderDiscount = criteria.discount.isPercentDiscount ? totalOrderAmount * (criteria.discount.value / 100) : criteria.discount.value;
            }
            return(orderDiscount);
        }
 public void OrderAmountDiscountCriteriaDataValidation(OrderAmountDiscountCriteria orderAmountDiscountCriteria)
 {
     if (string.IsNullOrEmpty(orderAmountDiscountCriteria.uniqueCode))
     {
         throw new OrderAmountDiscountCriteriaValidationExceptions("The Unique Code cannot be null or empty");
     }
     if (orderAmountDiscountCriteria.baseAmount <= 0)
     {
         throw new OrderAmountDiscountCriteriaValidationExceptions("The Amount Base cannot be zero [0].");
     }
     if (this.orderAmountDiscountCriterias.Where(p => p.uniqueCode == orderAmountDiscountCriteria.uniqueCode).ToList().Count > 0)
     {
         throw new OrderAmountDiscountCriteriaValidationExceptions("The entry Unique Code already exists ");
     }
 }
        public OrderAmountDiscountCriteria GetOrderAmountDiscountByTotalAmount(double orderAmount)
        {
            OrderAmountDiscountCriteria discountCriteria = null;
            double valueTemp = orderAmount;

            foreach (OrderAmountDiscountCriteria criteria in GetAllOrderAmountDiscountCriteria())
            {
                if (criteria.baseAmount <= orderAmount)
                {
                    double difference = (orderAmount - criteria.baseAmount);
                    if (difference < valueTemp)
                    {
                        valueTemp        = difference;
                        discountCriteria = criteria;
                    }
                }
            }
            return(discountCriteria);
        }
Exemple #4
0
 public ResponseService AddOrderAmountDiscountCriteria(OrderAmountDiscountCriteria orderAmount)
 {
     try
     {
         this.orderAmount.OrderAmountDiscountCriteriaDataValidation(orderAmount);
         this.orderAmount.AddAmountCriteria(orderAmount);
         // Return ok value using the generic return class
         responseTemplate.SetOKResponse("Discount order by amount  created successfully");
         return(responseTemplate);
     }
     catch (OrderAmountDiscountCriteriaValidationExceptions e)
     {
         responseTemplate.SetErrorResponse(e.Message);
         return(responseTemplate);
     }
     catch (Exception e)
     {
         traceLogs.SaveErrorLogs(e);
         responseTemplate.SetErrorResponse(_message: "GENERAL ERROR REMOVING PRODUCT FROM COMBO");
         return(responseTemplate);
     }
 }
 public void DeleteAmountCriteria(OrderAmountDiscountCriteria orderAmountDiscountCriteria)
 {
     this.orderAmountDiscountCriterias.Remove(orderAmountDiscountCriteria);
 }
 public void AddAmountCriteria(OrderAmountDiscountCriteria orderAmountDiscountCriteria)
 {
     this.orderAmountDiscountCriterias.Add(orderAmountDiscountCriteria);
 }