public PromotionFormulaResponseModel AddPromotion(PromotionFormulaRequestModel request) { PromotionBusiness promotionBusiness = new PromotionBusiness(); using (PromotionEngineEntities query = new PromotionEngineEntities()) { Promotion promotion = new Promotion { PromotionName = request.PromotionName }; foreach (FormulaRequestModel formula in request.PromotionFormulas) { promotion.PromotionFormulas.Add( new PromotionFormula { PromotionId = promotion.PromotionId, ItemQty = formula.ItemQty, ItemNames = formula.ItemNames, PromotionValue = formula.PromotionValue, FormulaDescription = formula.FormulaDescription, }); } query.Promotions.Add(promotion); query.SaveChanges(); //Retrieve SKU Promotion data from database return(promotionBusiness.GetPromotion(promotion.PromotionId)); } }
public PromotionFormulaResponseModel GetPromotion(int promotionId) { PromotionBusiness promotionBusiness = new PromotionBusiness(); //Retrieve SKU Promotion data from database return(promotionBusiness.GetPromotion(promotionId)); }
public void TestApplyPromotionThreeFor10() { var cartItem = new DTOCartItem() { Item = new Item() { Id = 0, Name = "", Price = 4.0m, Promotion = 2 }, Count = 3 }; decimal result = new PromotionBusiness().ApplyPromotion(cartItem); object.Equals(result, 10.0m); }
public void TestApplyPromotionBuyOneGetOneFree() { var cartItem = new DTOCartItem() { Item = new Item() { Id = 0, Name = "", Price = 2.0m, Promotion = 1 }, Count = 2 }; decimal result = new PromotionBusiness().ApplyPromotion(cartItem); object.Equals(result, 2.0m); }
public void TestApplyNoPromotion() { var cartItem = new DTOCartItem() { Item = new Item() { Id = 0, Name = "", Price = 3.0m, Promotion = 0 }, Count = 2 }; decimal result = new PromotionBusiness().ApplyPromotion(cartItem); object.Equals(result, 3.0m); }
public IEnumerable<Promotion> GetPromotionsAvailables() { IAvailable<Promotion> business = new PromotionBusiness(); return business.GetAvailables(); }
public IEnumerable<Promotion> GetPromotions() { IReader<Promotion> business = new PromotionBusiness(); return business.Get(); }
public Promotion GetPromotion(int code) { IReader<Promotion> business = new PromotionBusiness(); return business.Get(code); }
public void EditPromotion(Promotion element, string username, string password) { IManager<Promotion> business = new PromotionBusiness(); business.Edit(element, username, password); }
public void DeletePromotion(int code, string username, string password) { IManager<Promotion> business = new PromotionBusiness(); business.Delete(code, username, password); }
public int AddPromotion(Promotion element, string username, string password) { IManager<Promotion> business = new PromotionBusiness(); return business.Add(element, username, password); }
public PromotionResponseModel ApplyPromotion(PromotionRequestModel request) { PromotionResponseModel response = new PromotionResponseModel(); PromotionBusiness promotionBusiness = new PromotionBusiness(); response.TotalCost = 0; //Retrieve SKU Promotion data from database response.PromotionApplied = promotionBusiness.GetPromotion(request.PromotionId); using (PromotionEngineEntities query = new PromotionEngineEntities()) { //Retrieve SKU price from databse var dbItems = (from cartItems in request.CartItems join items in query.Items on cartItems.ItemName equals items.ItemName select new { cartItems.ItemQty, items.ItemName, items.ItemPrice }).ToList(); foreach (FormulaResponseModel formula in response.PromotionApplied.PromotionFormulas) { string[] formulaItemNames = formula.ItemNames.Split('&'); //Logic to calculate the purchase of 'n' items of a SKU for a fixed price if (formulaItemNames.Length > 0 && formulaItemNames.Length == 1) { foreach (var dbitem in dbItems) { if (dbitem.ItemName == formulaItemNames.Single()) { response.TotalCost += (((dbitem.ItemQty - (dbitem.ItemQty % formula.ItemQty)) / (formula.ItemQty)) * formula.PromotionValue) + ((dbitem.ItemQty % formula.ItemQty) * dbitem.ItemPrice); } } } //Logic to calculate the purchase of SKU 1 & SKU 2 ,.SKU 'n' for a fixed price else if (formulaItemNames.Length > 1) { var filteredDBItems = (from filtereddbItems in dbItems join filter in formulaItemNames on filtereddbItems.ItemName equals filter select new { filtereddbItems.ItemQty, filtereddbItems.ItemName, filtereddbItems.ItemPrice }).ToList(); if (formulaItemNames.Length == filteredDBItems.Count()) { int itemsFixedPrice = filteredDBItems.Min(q => q.ItemQty); response.TotalCost += itemsFixedPrice * formula.PromotionValue; foreach (var item in filteredDBItems) { response.TotalCost += ((item.ItemQty - itemsFixedPrice) * item.ItemPrice); } } else { foreach (var item in filteredDBItems) { response.TotalCost += (item.ItemQty * item.ItemPrice); } } } } } return(response); }