float ApplyPromotion(PromotionOffer promotions, Dictionary <string, int> SalesInvoice) { if (promotions.productOffer.Count == 1)// Single promotion { var key = promotions.productOffer.ElementAt(0).Key; if (SalesInvoice.ContainsKey(key)) { int quantityInvoice = SalesInvoice[key]; int offerQuantity = promotions.productOffer[key]; int offerscount = quantityInvoice / offerQuantity; int remainingQuantity = quantityInvoice % offerQuantity; SalesInvoice[key] = remainingQuantity; return(offerscount * promotions.OfferPrice); } } else { // Combi product promotion var key1 = promotions.productOffer.ElementAt(0).Key; var key2 = promotions.productOffer.ElementAt(1).Key;; if (SalesInvoice.ContainsKey(key1) && SalesInvoice.ContainsKey(key2)) { int quantityInvoice1 = SalesInvoice[key1]; int offerQuantity1 = promotions.productOffer[key1]; int offerscount1 = quantityInvoice1 / offerQuantity1; int remainingQuantity1 = quantityInvoice1 % offerQuantity1; int quantityInvoice2 = SalesInvoice[key2]; int offerQuantity2 = promotions.productOffer[key2]; int offerscount2 = quantityInvoice2 / offerQuantity2; int remainingQuantity2 = quantityInvoice2 % offerQuantity2; if (offerscount1 <= offerscount2) { SalesInvoice[key1] = remainingQuantity1; SalesInvoice[key2] = remainingQuantity2 + (offerQuantity2 * (offerscount2 - offerscount1)); return(offerscount1 * promotions.OfferPrice); } else { SalesInvoice[key1] = remainingQuantity1 + (offerQuantity1 * (offerscount1 - offerscount2)); SalesInvoice[key2] = remainingQuantity2; return(offerscount2 * promotions.OfferPrice); } } } return(0); }
public Promotions() { PromotionOffer A = new PromotionOffer(); A.productOffer.Add("A", 3); A.OfferPrice = 130; list_of_promotions.Add(A); PromotionOffer B = new PromotionOffer(); B.productOffer.Add("B", 2); B.OfferPrice = 45; list_of_promotions.Add(B); PromotionOffer CD = new PromotionOffer(); CD.productOffer.Add("C", 1); CD.productOffer.Add("D", 1); CD.OfferPrice = 30; list_of_promotions.Add(CD); }
public List <PromotionOffer> GetAllPromotionOffers() { List <PromotionOffer> lstPromotions = new List <PromotionOffer>(); PromotionOffer A = new PromotionOffer(); A.productOffer.Add("A", 3); A.OfferPrice = 130; lstPromotions.Add(A); PromotionOffer B = new PromotionOffer(); B.productOffer.Add("B", 2); B.OfferPrice = 45; lstPromotions.Add(B); PromotionOffer CD = new PromotionOffer(); CD.productOffer.Add("C", 1); CD.productOffer.Add("D", 1); CD.OfferPrice = 30; lstPromotions.Add(CD); return(lstPromotions); }