public void Run() { Category electronic = new Category(CategoryType.Electronic); Category book = new Category(CategoryType.Books); Product television = new Product("Television", 1000, electronic); Product essentialCSharp = new Product("TestBook", 400, book); _shoppingCart.AddProduct(television, 6); _shoppingCart.AddProduct(essentialCSharp, 5); Coupon coupon = CouponFactory.GenerateCoupon(1000, 20, CouponType.Rate); // I have created 2 discounts type for electronic and book categories. // the expectation is to find the best discount option in the same category. Campaign campaign3 = CampaignFactory.GenerateCampaign(electronic, 5, 50, DiscountType.Rate); Campaign campaign = CampaignFactory.GenerateCampaign(electronic, 2, 20, DiscountType.Rate); Campaign campaign2 = CampaignFactory.GenerateCampaign(book, 2, 5, DiscountType.Amount); Campaign campaign4 = CampaignFactory.GenerateCampaign(book, 4, 15, DiscountType.Amount); Campaign[] campaigns = { campaign2, campaign, campaign3, campaign4 }; _shoppingCart.ApplyCampaigns(campaigns); _shoppingCart.ApplyCoupon(coupon); _shoppingCart.Print(); var deliveryCost = _costCalculator.CalculateCost(50, 2, _shoppingCart); var totalCartAmount = _shoppingCart.GetTotalAmount(); var appliedCampaignDiscount = _shoppingCart.GetCampaignDiscount(); var appliedCouponDiscount = _shoppingCart.GetCouponDiscount(); WriteSummaryText(deliveryCost, totalCartAmount, appliedCampaignDiscount, appliedCouponDiscount); }
/// <summary> /// Voeg een product toe in een mandje en bereken de totaalprijs. /// </summary> /// <param name="userId">ID van de gebruiker</param> /// <param name="prodId">ID van het product</param> /// <param name="count">Aantal exemplaren van het betreffende product</param> /// <param name="type">Soort type van product</param> /// <returns></returns> public WinkelwagenDTO AddProduct(string userId, int prodId, int count, string type) { CheckIfKlantExists(userId); var winkelwagen = _repositoryWinkelwagen.AddProduct(userId, prodId, count, type); //Herberekenen van de totaal prijs winkelwagen.TotaalPrijs = _calculator.CalculateCost(winkelwagen); try { _repositoryWinkelwagen.SaveChanges(); } catch (Exception e) { throw new Exception(e.Message); } return(_winkelwagenMapper.MapToDTO(winkelwagen)); }
public Line(Bike bike, int quantity, ICostCalculator costCalculator) { _costCalculator = costCalculator; Brand = bike.Brand; Model = bike.Model; Price = bike.Price; Quantity = quantity; Cost = _costCalculator.CalculateCost(quantity, Price); }
public RentCostsBuilder CalculatePaymentDetails(Flat flat) { _hotWaterCostsCalculator.Initialize(flat); _coldWaterCostsCalculator.Initialize(flat); _heatingWaterCostsCalculator.Initialize(flat); _administrationCostsCalculator.Initialize(flat); _garbageCostsCalculator.Initialize(flat); _payment.AdministrationValue = _administrationCostsCalculator.CalculateCost(); _payment.AdministrationDescription = _administrationCostsCalculator.GetDescription(); _payment.GarbageValue = _garbageCostsCalculator.CalculateCost(); _payment.GarbageDescription = _garbageCostsCalculator.GetDescription(); _payment.ColdWaterValue = _coldWaterCostsCalculator.CalculateCost(); _payment.ColdWaterDescription = _coldWaterCostsCalculator.GetDescription(); _payment.HotWaterValue = _hotWaterCostsCalculator.CalculateCost(); _payment.HotWaterDescription = _hotWaterCostsCalculator.GetDescription(); _payment.HeatingValue = _heatingWaterCostsCalculator.CalculateCost(); _payment.HeatingDescription = _heatingWaterCostsCalculator.GetDescription(); return(this); }
public BestellingDTO AddBestellingToCustomer(string custId) { var bestelling = new BestellingCreateUpdateDTO { Producten = new List <BestellingItem>(), Datum = DateTime.Now, Klant = _klantRepository.GetKlantByID(custId) }; var winkelwagenGebruiker = _repositoryWinkelwagen.GetWinkelwagenByKlantId(custId); foreach (VerkoopItem item in winkelwagenGebruiker.Producten) { bestelling.Producten.Add(new BestellingItem() { Aantal = item.Aantal, Product = item.Product }); } bestelling.TotaalPrijs = _costCalculator.CalculateCost(winkelwagenGebruiker); var newBestelling = _bestellingMapper.MapToModel(bestelling); var createdBestelling = _repositoryBestelling.AddBestellingToCustomer(newBestelling); winkelwagenGebruiker.TotaalPrijs = 0.0; winkelwagenGebruiker.Producten = new List <WinkelwagenItem>(); try { _repositoryBestelling.SaveChanges(); } catch (DbUpdateException) { return(null); } catch (Exception e) { throw new Exception(e.Message); } return(_bestellingMapper.MapToDTO(createdBestelling)); }
public void Run() { Category electronic = new Category(CategoryType.Electronic); Category book = new Category(CategoryType.Books); Product television = new Product("Television", 1000, electronic); Product essentialCSharp = new Product("EssentialCSharp", 400, book); _shoppingCart.AddProduct(television, 5); _shoppingCart.AddProduct(essentialCSharp, 1); Coupon coupon = CouponFactory.GenerateCoupon(1000, 20, DiscountType.Rate); Campaign campaign = CampaignFactory.GenerateCampaign(electronic, 2, 10, DiscountType.Amount); _shoppingCart.ApplyCampaigns(campaign); _shoppingCart.Print(); var deliveryCost = _costCalculator.CalculateCost(50, 2, _shoppingCart); var totalCartAmount = _shoppingCart.GetTotalAmount(); WriteClosingText(deliveryCost, totalCartAmount); }