public void SaveInfo(int pvId) { ProductVariant productVariant = ProductManager.GetProductVariantById(pvId); if (productVariant != null) { List <int> selectedDiscountIds = this.DiscountMappingControl.SelectedDiscountIds; var existingDiscounts = DiscountManager.GetDiscountsByProductVariantId(productVariant.ProductVariantId); var allDiscounts = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToSKUs); foreach (Discount discount in allDiscounts) { if (selectedDiscountIds.Contains(discount.DiscountId)) { if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) == null) { DiscountManager.AddDiscountToProductVariant(productVariant.ProductVariantId, discount.DiscountId); } } else { if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) != null) { DiscountManager.RemoveDiscountFromProductVariant(productVariant.ProductVariantId, discount.DiscountId); } } } } }
public void CalculateTheTicketPrice() { try { ProductViewManager productViewManager = new ProductViewManager(); ProductLineManager productLineManager = new ProductLineManager(); DiscountManager discountManager = new DiscountManager(); CashRegisterManager.MakeASalesCycle(productViewManager.SelectAProductByRow(ArticleToSellDataGrid.CurrentCell.Item), CashRegisterManager, InvoiceManager, productLineManager, discountManager, SalesParametersWindow.SalesParameter.Quantity, SalesParametersWindow.SalesParameter.PourcentDiscount, SalesParametersWindow.SalesParameter.Discount); InvoiceDataGrid.ItemsSource = CashRegisterManager.InvoiceViewsList; Payment.TotalToPay = Math.Round(InvoiceManager.Ticket.TotalToPay, 2); TotalTxtBlock.Text = $"{Math.Round(InvoiceManager.Ticket.Recipe, 2)}€ TTC"; RestToPayTxtBlock.Text = $"{Math.Round(Payment.TotalToPay, 2)}€"; if (CashRegisterManager.CalculateTheTotalInvoiceDiscount(InvoiceManager.Ticket) > 0) { DiscountTxtBlock.Text = "Remise"; TotalDiscountTxtBlock.Text = $"-{Math.Round(CashRegisterManager.CalculateTheTotalInvoiceDiscount(InvoiceManager.Ticket), 2)}"; } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
void BindGrid() { DiscountCollection discountCollection = DiscountManager.GetAllDiscounts(null); gvDiscounts.DataSource = discountCollection; gvDiscounts.DataBind(); }
static void Main(string[] args) { UserManager userManager = new UserManager(new MernisServiceAdapter()); User userElif = new User(1, "bilcom87", "123456", "elif", "baydi", new DateTime(1900, 1, 1), "12345678990"); userManager.Add(userElif); Console.WriteLine(); GameManager gameManager = new GameManager(); Game gameAsphalt = new Game(1, "Asphalt", 20); Game gameGta = new Game(1, "GTA", 10.75); Game gameSims = new Game(1, "Sims", 25.50); gameManager.AddMultiple(new Game[] { gameAsphalt, gameGta, gameSims }); Console.WriteLine(); DiscountManager discountManager = new DiscountManager(); Discount discountSpring = new Discount("Bahar", 10, new DateTime(2021, 7, 15)); Discount discountWinter = new Discount("Ara Tatil", 10, new DateTime(2021, 1, 15)); discountManager.Add(discountSpring); discountManager.Add(discountWinter); Console.WriteLine(); SalesManager salesManager = new SalesManager(userManager, discountManager); salesManager.Sold(gameGta, userElif); salesManager.Sold(gameSims, userElif, discountSpring); salesManager.Sold(gameAsphalt, userElif, discountWinter); Console.WriteLine(); userManager.GetGames(userElif); Console.ReadLine(); }
static void Main(string[] args) { //var dc = new DiscountManager(); //var dc = new DiscountManager(new DefaultAccountDiscountCalculatorFactory(), new DefaultLoyaltyDiscountCalculator()); var discountsDictionary = new Dictionary <AccountStatus, IAccountDiscountCalculator> { { AccountStatus.NotRegistered, new NotRegisteredDiscountCalculator() }, { AccountStatus.SimpleCustomer, new SimpleCustomerDiscountCalculator() }, { AccountStatus.ValuableCustomer, new ValuableCustomerDiscountCalculator() }, { AccountStatus.MostValuableCustomer, new MostValuableCustomerDiscountCalculator() } }; var dc = new DiscountManager(new DictionarableAccountDiscountCalculatorFactory(discountsDictionary), new DefaultLoyaltyDiscountCalculator()); Action <DiscountManager, AccountStatus> perform = PerformCalculation; AccountStatus status = AccountStatus.NotRegistered; perform(dc, status); status = AccountStatus.SimpleCustomer; perform(dc, status); status = AccountStatus.ValuableCustomer; perform(dc, status); status = AccountStatus.MostValuableCustomer; perform(dc, status); Console.ReadKey(); }
public void SaveInfo(int catId) { Category category = CategoryManager.GetCategoryById(catId); if (category != null) { List <int> selectedDiscountIds = this.DiscountMappingControl.SelectedDiscountIds; var existingDiscounts = DiscountManager.GetDiscountsByCategoryId(category.CategoryId); var allDiscounts = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToCategories); foreach (Discount discount in allDiscounts) { if (selectedDiscountIds.Contains(discount.DiscountId)) { if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) == null) { DiscountManager.AddDiscountToCategory(category.CategoryId, discount.DiscountId); } } else { if (existingDiscounts.Find(d => d.DiscountId == discount.DiscountId) != null) { DiscountManager.RemoveDiscountFromCategory(category.CategoryId, discount.DiscountId); } } } } }
public EmployeeController() { this._employeeManager = new EmployeeManager(); this._employeeDependentManager = new EmployeeDependentManager(this._employeeManager); this._benefitManager = new BenefitManager(this._employeeDependentManager); this._discountManager = new DiscountManager(this._benefitManager); }
void BindGrid() { var discounts = DiscountManager.GetAllDiscounts(null); gvDiscounts.DataSource = discounts; gvDiscounts.DataBind(); }
private void BindData() { Discount discount = DiscountManager.GetDiscountByID(this.DiscountID); if (discount != null) { CommonHelper.SelectListItem(this.ddlDiscountType, discount.DiscountTypeID); CommonHelper.SelectListItem(this.ddlDiscountRequirement, discount.DiscountRequirementID); this.txtName.Text = discount.Name; this.cbUsePercentage.Checked = discount.UsePercentage; this.txtDiscountPercentage.Value = discount.DiscountPercentage; this.txtDiscountAmount.Value = discount.DiscountAmount; this.cStartDateButtonExtender.SelectedDate = discount.StartDate; this.cEndDateButtonExtender.SelectedDate = discount.EndDate; this.cbRequiresCouponCode.Checked = discount.RequiresCouponCode; this.txtCouponCode.Text = discount.CouponCode; CustomerRoleCollection customerRoles = discount.CustomerRoles; List <int> _customerRoleIDs = new List <int>(); foreach (CustomerRole customerRole in customerRoles) { _customerRoleIDs.Add(customerRole.CustomerRoleID); } CustomerRoleMappingControl.SelectedCustomerRoleIDs = _customerRoleIDs; CustomerRoleMappingControl.BindData(); } else { List <int> _customerRoleIDs = new List <int>(); CustomerRoleMappingControl.SelectedCustomerRoleIDs = _customerRoleIDs; CustomerRoleMappingControl.BindData(); } }
protected void ApplyDiscountCouponCode() { string couponCode = this.txtDiscountCouponCode.Text.Trim(); if (String.IsNullOrEmpty(couponCode)) { return; } var discounts = DiscountManager.GetAllDiscounts(null); var discount = discounts.FindByCouponCode(couponCode); bool isDiscountValid = discount != null; if (isDiscountValid) { pnlDiscountWarnings.Visible = false; lblDiscountWarning.Visible = false; CustomerManager.ApplyDiscountCouponCode(couponCode); this.BindData(); } else { pnlDiscountWarnings.Visible = true; lblDiscountWarning.Visible = true; lblDiscountWarning.Text = GetLocaleResourceString("ShoppingCart.DiscountCouponCode.WrongDiscount"); } }
static void Main(string[] args) { GamerManager gamerManager = new GamerManager(new GamerCheckManager()); Gamer gamer1 = new Gamer { GamerID = 1, BirthYear = 2000, GamerFirstName = "SENEM", GamerLastName = "SERBEST", NationalIdentity = 1234567890, GamerUserName = "******" }; gamerManager.Add(gamer1); Game game1 = new Game { GameId = 3, GameName = " Disco Elysium ", GamePrice = 33.55 }; Game game2 = new Game { GameId = 4, GameName = " Portal ", GamePrice = 18.50 }; Campaign campaign1 = new Campaign { CampaignName = "New Year Campaign", DiscountRate = 80 }; Campaign campaign2 = new Campaign { CampaignName = "Gaming Festival Campaign", DiscountRate = 50 }; DiscountManager discountManager = new DiscountManager(); discountManager.Discount(game1, gamer1, campaign2); CampaignManager campaignManager = new CampaignManager(); campaignManager.Add(campaign2); campaignManager.Delete(campaign1); }
public IActionResult setDiscount([FromForm] DiscountDTO discountDTO) { if (discountDTO == null) { return(BadRequest(new JsonCreate() { message = Utils.ConstMessage.BAD_REQUEST, data = false })); } DiscountManager discount = new DiscountManager(); bool judge = discount.insertNewDiscount(discountDTO); if (judge) { return(Ok(new JsonCreate() { message = Utils.ConstMessage.INSERT_SUCCESS, data = judge })); } else { return(Conflict(new JsonCreate() { message = Utils.ConstMessage.CONFILICT, data = false })); } }
private void FillDropDowns() { this.ddlDiscountType.Items.Clear(); DiscountTypeCollection discountTypes = DiscountManager.GetAllDiscountTypes(); foreach (DiscountType discountType in discountTypes) { ListItem item2 = new ListItem(discountType.Name, discountType.DiscountTypeId.ToString()); this.ddlDiscountType.Items.Add(item2); } this.ddlDiscountRequirement.Items.Clear(); DiscountRequirementCollection discountRequirements = DiscountManager.GetAllDiscountRequirements(); foreach (DiscountRequirement discountRequirement in discountRequirements) { ListItem item2 = new ListItem(discountRequirement.Name, discountRequirement.DiscountRequirementId.ToString()); this.ddlDiscountRequirement.Items.Add(item2); } this.ddlDiscountLimitation.Items.Clear(); DiscountLimitationCollection discountLimitations = DiscountManager.GetAllDiscountLimitations(); foreach (DiscountLimitation discountLimitation in discountLimitations) { ListItem item2 = new ListItem(discountLimitation.Name, discountLimitation.DiscountLimitationId.ToString()); this.ddlDiscountLimitation.Items.Add(item2); } }
public void SetUp() { var compilerDataExpected = new CompilerData().Pairs.Select(x => x.Second); _discountManager = new DiscountManager(compilerDataExpected); _shoppingBasket = new Basket(_discountManager); }
public DiscountManagerImpl(DiscountManager discountManager) { this.discountManager = discountManager; dao = DiscountDao.getInstance(); itemManagerImpl = new ItemManagerImpl(); companyManagerImpl = new CompanyManagerImpl(); categoryManagerImpl = new CategoryManagerImpl(); }
/// <summary> /// Gets a preferred discount /// </summary> /// <param name="productVariant">Product variant</param> /// <param name="customer">Customer</param> /// <param name="AdditionalCharge">Additional charge</param> /// <returns>Preferred discount</returns> protected static Discount GetPreferredDiscount(ProductVariant productVariant, Customer customer, decimal AdditionalCharge) { DiscountCollection allowedDiscounts = GetAllowedDiscounts(productVariant, customer); decimal finalPriceWithoutDiscount = GetFinalPrice(productVariant, customer, AdditionalCharge, false); Discount preferredDiscount = DiscountManager.GetPreferredDiscount(allowedDiscounts, finalPriceWithoutDiscount); return(preferredDiscount); }
protected void DeleteUsageHistoryButton_OnCommand(object sender, CommandEventArgs e) { if (e.CommandName == "DeleteUsageHistory") { DiscountManager.DeleteDiscountUsageHistory(Convert.ToInt32(e.CommandArgument)); BindUsageHistory(); } }
private void FillDropDowns() { //discunt types this.ddlDiscountType.Items.Clear(); var discountTypes = DiscountManager.GetAllDiscountTypes(); foreach (DiscountType discountType in discountTypes) { ListItem item2 = new ListItem(discountType.Name, discountType.DiscountTypeId.ToString()); this.ddlDiscountType.Items.Add(item2); } //discount requirements this.ddlDiscountRequirement.Items.Clear(); var discountRequirements = DiscountManager.GetAllDiscountRequirements(); foreach (DiscountRequirement discountRequirement in discountRequirements) { ListItem item2 = new ListItem(discountRequirement.Name, discountRequirement.DiscountRequirementId.ToString()); this.ddlDiscountRequirement.Items.Add(item2); } //discount limitations this.ddlDiscountLimitation.Items.Clear(); var discountLimitations = DiscountManager.GetAllDiscountLimitations(); foreach (DiscountLimitation discountLimitation in discountLimitations) { ListItem item2 = new ListItem(discountLimitation.Name, discountLimitation.DiscountLimitationId.ToString()); this.ddlDiscountLimitation.Items.Add(item2); } //required billing countries this.ddlRequirementBillingCountryIs.Items.Clear(); ListItem rbciEmpty = new ListItem(GetLocaleResourceString("Admin.DiscountInfo.RequirementBillingCountryIs.SelectCountry"), "0"); this.ddlRequirementBillingCountryIs.Items.Add(rbciEmpty); var billingCountries = CountryManager.GetAllCountriesForBilling(); foreach (Country country in billingCountries) { ListItem ddlCountryItem2 = new ListItem(country.Name, country.CountryId.ToString()); this.ddlRequirementBillingCountryIs.Items.Add(ddlCountryItem2); } //required shipping countries this.ddlRequirementShippingCountryIs.Items.Clear(); ListItem rsciEmpty = new ListItem(GetLocaleResourceString("Admin.DiscountInfo.RequirementShippingCountryIs.SelectCountry"), "0"); this.ddlRequirementShippingCountryIs.Items.Add(rsciEmpty); var shippingCountries = CountryManager.GetAllCountriesForShipping(); foreach (Country country in shippingCountries) { ListItem ddlCountryItem2 = new ListItem(country.Name, country.CountryId.ToString()); this.ddlRequirementShippingCountryIs.Items.Add(ddlCountryItem2); } }
private static void PerformCalculation(DiscountManager dc, AccountStatus status) { decimal priceWithDiscount = 0; string message = string.Empty; priceWithDiscount = dc.ApplyDiscount(20000, status, 3); message = $"{status.GetAttributeDescription()}, 20000, 3 years, {priceWithDiscount}"; Console.WriteLine(message); }
static void Main(string[] args) { User user1 = new User(1, "Vuqar", "Rahimli", new DateTime(1998, 4, 13), "654681351"); // creating new customer CustomerManager customerManager = new CustomerManager(new MernisServiceAdapter()); // registering if values are real customerManager.Register(user1); customerManager.Update(user1); // updating customer customerManager.Delete(user1); // deleting customer from system // creating new products Product product1 = new Game(1, "Mafia 2", new DateTime(2021, 1, 15), 30.99, "Bestseller"); Product product2 = new Game(2, "Witcher 3", new DateTime(2021, 3, 10), 50.99, "Bestseller"); Product product3 = new Game(3, "Skyrim", new DateTime(2021, 4, 1), 21.99, "Bestseller"); Product product4 = new Game(4, "Total Overdose", new DateTime(2021, 2, 24), 15.89, "Bestseller"); Product product5 = new Game(4, "Erzurum", new DateTime(2021, 1, 24), 30, "Bestseller"); // creating a campaign Campaign campaign = new Campaign(); campaign.DiscountRate = 100; // defining discount rate //---------------------------------------------------------------------------------------------------------- // HATALI gibi gözüken kısım campaign.products = new List <Product>() { product2, product5 }; // applying campaign to certain products CampaignManager campaignManager = new DiscountManager(new DiscountCheck()); // checking if products have discount on them to calculate the discount campaignManager.AddCampaign(campaign); // adding campaigns // bu kısım biraz saçma oldu ama daha iyi nasıl yaparım, discount calcualate methodunu başka yere mi taşımam lazım, // tam kestiremedim, çok fazla class oluşturdum sanki. // bu yaptığım ne gibi sorunlara yol aça bilir? // esas campaign manager ve discount manager classlarında bozdum sanırım, daha iyi nasıl yapabilirim? //--------------------------------------------------------------------------------------------------------------------------------- SaleManager saleManager = new SaleManager(); saleManager.Sell(product1, campaign, user1); saleManager.Sell(product2, campaign, user1); saleManager.Sell(product3, campaign, user1); saleManager.Sell(product4, campaign, user1); saleManager.Sell(product5, campaign, user1); }
public IActionResult getDiscountAll() { DiscountManager discountManager = new DiscountManager(); List <DiscountDTO> discountDTOs = discountManager.getDiscountDTOs(); return(Ok(new JsonCreate() { message = Utils.ConstMessage.GET_SUCCESS, data = discountDTOs })); }
public IActionResult getDiscountById(String medicineId) { DiscountManager discountManager = new DiscountManager(); List <DiscountDTO> discountDTOs = discountManager.getDiscountDTOById(medicineId); return(Ok(new JsonCreate() { message = Utils.ConstMessage.GET_SUCCESS, data = discountDTOs })); }
private void BindUsageHistory() { Discount discount = DiscountManager.GetDiscountById(this.DiscountId); if (discount != null) { gvDiscountUsageHistory.DataSource = DiscountManager.GetAllDiscountUsageHistoryEntries(discount.DiscountId, null, null); gvDiscountUsageHistory.DataBind(); } }
protected void DeleteButton_Click(object sender, EventArgs e) { try { DiscountManager.MarkDiscountAsDeleted(this.DiscountID); Response.Redirect("Discounts.aspx"); } catch (Exception exc) { ProcessException(exc); } }
public IActionResult deleteDiscount(int discountId) { DiscountManager discountManager = new DiscountManager(); bool judge = discountManager.deleteDiscount(discountId); if (judge) { return(Ok(JsonCreate.newInstance(Utils.ConstMessage.DELETE_SUCCESS, judge))); } else { return(Conflict(JsonCreate.newInstance(Utils.ConstMessage.DELETE_FAIL, judge))); } }
public void BindData(DiscountTypeEnum?DiscountType) { var discounts = DiscountManager.GetAllDiscounts(DiscountType); foreach (Discount discount in discounts) { ListItem item = new ListItem(discount.Name, discount.DiscountId.ToString()); if (this.selectedDiscountIds.Contains(discount.DiscountId)) { item.Selected = true; } this.cblDiscounts.Items.Add(item); } this.cblDiscounts.DataBind(); }
/// <summary> /// Gets allowed discounts /// </summary> /// <param name="productVariant">Product variant</param> /// <param name="customer">Customer</param> /// <returns>Discounts</returns> protected static List <Discount> GetAllowedDiscounts(ProductVariant productVariant, Customer customer) { var allowedDiscounts = new List <Discount>(); string customerCouponCode = string.Empty; if (customer != null) { customerCouponCode = customer.LastAppliedCouponCode; } foreach (var _discount in productVariant.AllDiscounts) { if (_discount.IsActive(customerCouponCode) && _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs && !allowedDiscounts.ContainsDiscount(_discount.Name)) { //discount requirements if (_discount.CheckDiscountRequirements(customer) && _discount.CheckDiscountLimitations(customer)) { allowedDiscounts.Add(_discount); } } } var productCategories = CategoryManager.GetProductCategoriesByProductId(productVariant.ProductId); foreach (var _productCategory in productCategories) { var _categoryDiscounts = DiscountManager.GetDiscountsByCategoryId(_productCategory.CategoryId); foreach (var _discount in _categoryDiscounts) { if (_discount.IsActive(customerCouponCode) && _discount.DiscountType == DiscountTypeEnum.AssignedToCategories && !allowedDiscounts.ContainsDiscount(_discount.Name)) { //discount requirements if (_discount.CheckDiscountRequirements(customer) && _discount.CheckDiscountLimitations(customer)) { allowedDiscounts.Add(_discount); } } } } return(allowedDiscounts); }
public void SaveInfo() { Category category = CategoryManager.GetCategoryByID(this.CategoryID); if (category != null) { foreach (Discount discount in DiscountManager.GetDiscountsByCategoryID(category.CategoryID)) { DiscountManager.RemoveDiscountFromCategory(category.CategoryID, discount.DiscountID); } foreach (int discountID in DiscountMappingControl.SelectedDiscountIDs) { DiscountManager.AddDiscountToCategory(category.CategoryID, discountID); } } }
public void SaveInfo() { ProductVariant productVariant = ProductManager.GetProductVariantByID(ProductVariantID); if (productVariant != null) { foreach (Discount discount in DiscountManager.GetDiscountsByProductVariantID(productVariant.ProductVariantID)) { DiscountManager.RemoveDiscountFromProductVariant(productVariant.ProductVariantID, discount.DiscountID); } foreach (int discountID in DiscountMappingControl.SelectedDiscountIDs) { DiscountManager.AddDiscountToProductVariant(productVariant.ProductVariantID, discountID); } } }
static void Main(string[] args) { IPlayerService playerManager = new PlayerManager(new PlayerValidationManager()); Player player = new Player { PlayerID = 1, Name = "Berk", Surname = "Şenel", Nickname = "DeuxBach", DateOfBirth = "09.10.1998", CitizenshipNumber = "123456789" }; playerManager.Add(player); Console.WriteLine("******"); IGameService gameManager = new GameManager(); Game game = new Game(); game.GameID = 1; game.Title = "Arma 3"; game.Price = 100; Game game1 = new Game(); game1.GameID = 2; game1.Title = "XCOM 2"; game1.Price = 120; gameManager.Add(game); gameManager.Add(game1); Console.WriteLine("******"); gameManager.Sell(game, player); Console.WriteLine("******"); Game[] games = new Game[] { game, game1 }; IDiscountService discountManager = new DiscountManager(); Discount discount = new Discount(); discount.ID = 1; discount.Percentage = 20; discount.Name = "Winter Sale"; discountManager.Add(discount); Console.WriteLine("******"); discountManager.Discount(games, discount); }
/// <summary> /// Gets a shipping discount /// </summary> /// <param name="customer">Customer</param> /// <param name="shippingTotal">Shipping total</param> /// <param name="appliedDiscount">Applied discount</param> /// <returns>Shipping discount</returns> public static decimal GetShippingDiscount(Customer customer, decimal shippingTotal, out Discount appliedDiscount) { decimal shippingDiscountAmount = decimal.Zero; string customerCouponCode = string.Empty; if (customer != null) { customerCouponCode = customer.LastAppliedCouponCode; } var allDiscounts = DiscountManager.GetAllDiscounts(DiscountTypeEnum.AssignedToShipping); var allowedDiscounts = new DiscountCollection(); foreach (var _discount in allDiscounts) { if (_discount.IsActive(customerCouponCode) && _discount.DiscountType == DiscountTypeEnum.AssignedToShipping && !allowedDiscounts.ContainsDiscount(_discount.Name)) { //discount requirements if (_discount.CheckDiscountRequirements(customer) && _discount.CheckDiscountLimitations(customer)) { allowedDiscounts.Add(_discount); } } } appliedDiscount = DiscountManager.GetPreferredDiscount(allowedDiscounts, shippingTotal); if (appliedDiscount != null) { shippingDiscountAmount = appliedDiscount.GetDiscountAmount(shippingTotal); } if (shippingDiscountAmount < decimal.Zero) { shippingDiscountAmount = decimal.Zero; } shippingDiscountAmount = Math.Round(shippingDiscountAmount, 2); return(shippingDiscountAmount); }