public IVoucherResponse Redeem(IList <IProduct> products, decimal appliedVouchers) { if (products.Where(x => x.ProductCatogery != ProductCatogery.GiftVoucher) .Sum(x => x.Price) > Threshold && products.Any(x => x.ProductCatogery == ProductCatogery)) { State = VoucherState.Redeemed; decimal discountAmount = VoucherPrice > products.Where(x => x.ProductCatogery == ProductCatogery).Sum(x => x.Price) ? products.Where(x => x.ProductCatogery == ProductCatogery).Sum(x => x.Price) : VoucherPrice; return(new VoucherResponse(true, discountAmount)); } else { State = VoucherState.Failed; ValidationMessage = products.Any(x => x.ProductCatogery == ProductCatogery)? $"You have not reached the spend threshold for voucher {VoucherReference} . Spend another " + $"£{(Threshold - products.Where(x => x.ProductCatogery != ProductCatogery.GiftVoucher).Sum(x => x.Price) + decimal.Parse("0.01")).ToString("F")} " + $"to receive £{VoucherPrice.ToString("F")} from you basket total" : $"There are no products in your basket applicable to {Type.ToString()} Voucher {VoucherReference}."; return(new VoucherResponse(false, default(decimal))); } }
public void Print() { Console.WriteLine($"1 x £{VoucherPrice.ToString("F")} {VoucherType.Gift.ToString()} Voucher {VoucherReference} applied"); }
public IVoucherResponse Redeem(IList <IProduct> products, decimal appliedVouchers) { if (products.Where(x => x.ProductCatogery != ProductCatogery.GiftVoucher) .Sum(x => x.Price) > VoucherPrice + appliedVouchers) { State = VoucherState.Redeemed; return(new VoucherResponse(true, VoucherPrice)); } else { State = VoucherState.Failed; ValidationMessage = $"Basket total less than {VoucherType.Gift.ToString()} Voucher {VoucherReference} value £{VoucherPrice.ToString("F")}." + $" Spend another £{(VoucherPrice + appliedVouchers- products.Where(x => x.ProductCatogery != ProductCatogery.GiftVoucher).Sum(x => x.Price) + decimal.Parse("0.01")).ToString("F")} to apply this Voucher"; return(new VoucherResponse(false, default(decimal))); } }
public void Print() { Console.WriteLine($"1 x £{VoucherPrice.ToString("F")} off {ProductCatogery.ToString()} in baskets over £{Threshold.ToString("F")} {Type.ToString()} Voucher {VoucherReference} applied"); }