public decimal CalculateTotal(DiscountCard discountCard)
        {
            Contract.Requires(discountCard != null);

            decimal discountRate = discountCard.DiscountPercents / 100.0M;

            discountCard.AddTotal(DoCalculateTotal());
            return(DoCalculateTotal(discountRate));
        }
Пример #2
0
 private void EbarcodeKeyUp(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Return)
     {
         _info = null;
         _card = RepositoryDiscountCard.GetOneByNumber(BoxBarCode.Text);
         SetInfo();
     }
 }
Пример #3
0
        private void ManageCustomer(Customer customer, string operationStr)
        {
            if (String.IsNullOrEmpty(operationStr))
            {
                return;
            }

            Visible = false;
            using (var frmCustomer = new FrmCustomer())
            {
                DiscountCard discountCard = null;
                if (customer != null)
                {
                    frmCustomer.Customer = customer;
                    discountCard         = customer.FkDiscountCard;
                }

                if (frmCustomer.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        //Remove existing discount card of selected customer
                        if (discountCard != null)
                        {
                            _discountCardList.Remove(discountCard);
                        }
                        //Add new discount card of selected customer
                        if (frmCustomer.Customer.FkDiscountCard != null)
                        {
                            _discountCardList.Add(frmCustomer.Customer.FkDiscountCard);
                        }

                        //Customer
                        if (operationStr.Equals(Resources.OperationRequestInsert))
                        {
                            _customerList.Add(frmCustomer.Customer);
                        }
                        else
                        {
                            _customerList[_customerList.IndexOf(lsbCustomer.SelectedItem as Customer)] =
                                frmCustomer.Customer;
                        }

                        lsbCustomer.SelectedIndex = -1;
                        lsbCustomer.SelectedIndex = lsbCustomer.FindStringExact(frmCustomer.Customer.CustomerName);
                    }
                    catch (Exception exception)
                    {
                        FrmExtendedMessageBox.UnknownErrorMessage(
                            Resources.MsgCaptionUnknownError,
                            exception.Message);
                    }
                }
                Visible = true;
            }
        }
Пример #4
0
        public void AddCurrentSale_AfterAddingLastSale_AppliesNewDiscountPercent()
        {
            var discountCard = new DiscountCard(1500);
            var totalPriceWithOnePercentDiscount = discountCard.Apply(1000);

            discountCard.AddCurrentSale(1000);

            Assert.Equal(990, totalPriceWithOnePercentDiscount);
            Assert.Equal(970, discountCard.Apply(1000));
        }
Пример #5
0
        public void ApplyDiscountCard()
        {
            this._cart.Add(this._existingProduct);

            var discountCard = new DiscountCard(10);

            this._cart.ApplyCard(discountCard);

            this._cart.PriceWithDiscount.ShouldBe(2 * PRODUCT_PRICE_WITH_DISCOUNT);
            this._cart.FullPrice.ShouldBe(2 * PRODUCT_PRICE);
        }
Пример #6
0
        private static void SaveFile()
        {
            var root = new XElement("DiscountCards");

            foreach (var discountCard in DiscountCards)
            {
                root.Add(DiscountCard.ToXElement(discountCard));
            }

            File.WriteAllText(Path, new XDocument(root).ToString());
        }
Пример #7
0
        public async Task <IActionResult> Create([Bind("Id,type")] DiscountCard discountCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(discountCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(discountCard));
        }
        public async Task AddTest()
        {
            var fakeRepository = Mock.Of <IDiscountCardRepository>();
            var cardService    = new Services.DiscountCardService(fakeRepository);

            var card = new DiscountCard()
            {
                type = "test user 1"
            };
            await cardService.AddAndSave(card);
        }
Пример #9
0
        public void Checkout_WithDiscountCard_AmountOfSaleIsAddedToDiscountCard()
        {
            var sale         = new Sale();
            var discountCard = new DiscountCard(1000);

            sale.Add(new Product("A", 2000));
            sale.AddDiscountCard(discountCard);

            Assert.Equal(1, discountCard.CurrentPercent());
            Assert.Equal(1980, sale.Checkout());
            Assert.Equal(3, discountCard.CurrentPercent());
        }
Пример #10
0
        public void IncreaseAmount()
        {
            var discountCard = new DiscountCard(10);

            var amount = 20m;

            discountCard.IncreaseAmount(amount);
            discountCard.Amount.ShouldBe(amount);

            discountCard.IncreaseAmount(amount);
            discountCard.Amount.ShouldBe(2 * amount);
        }
Пример #11
0
        public void Checkout_WithDiscountCard_DiscountAppliesToProductIfVolumeIsNotReached()
        {
            var sale1        = new Sale();
            var discountCard = new DiscountCard(1000);
            var product      = new Product("A", 2000, new VolumeDiscount(3000, 2));

            sale1.Add(product);
            sale1.AddDiscountCard(discountCard);

            Assert.Equal(1, discountCard.CurrentPercent());
            Assert.Equal(1980, sale1.Checkout());
            Assert.Equal(3, discountCard.CurrentPercent());
        }
Пример #12
0
        private static void LoadFile()
        {
            if (File.Exists(Path))
            {
                var document = XDocument.Load(Path);

                DiscountCards.Clear();
                foreach (var element in document.GetXElements("DiscountCards", "rec"))
                {
                    DiscountCards.Add(DiscountCard.FromXElement(element));
                }
            }
        }
Пример #13
0
        public void Checkout_WithDiscountCard_NoDiscountForVolume()
        {
            var sale1        = new Sale();
            var product      = new Product("A", 2000, new VolumeDiscount(3000, 2));
            var discountCard = new DiscountCard(1000);

            sale1.Add(product);
            sale1.Add(product);
            sale1.AddDiscountCard(discountCard);

            Assert.Equal(1, discountCard.CurrentPercent());
            Assert.Equal(3000, sale1.Checkout());
            Assert.Equal(1, discountCard.CurrentPercent());
        }
Пример #14
0
        protected override void EditRecord()
        {
            Console.Write("Done");
            DiscountCard selectedCard = GetSelectedCard();

            if (selectedCard != null)
            {
                FormCardDetail form = new FormCardDetail();
                if (form.OpenRecord(selectedCard.RecordId))
                {
                    form.ShowDialog();
                    RefreshData();
                }
            }
        }
Пример #15
0
        protected override bool DeleteRecord()
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            DiscountCard c = dg.Select((int)client.CardId);

            c.ClientId = null;
            dg.Update(c);
            ClientFactory          clientFactory = new ClientFactory();
            ClientGateway <Client> cg            = (ClientGateway <Client>)clientFactory.GetClient();

            cg.Delete(client.RecordId);
            return(true);
        }
Пример #16
0
        private void InsertDiscountCard(DiscountCard discountCard)
        {
            if (discountCard == null)
            {
                throw new ArgumentNullException("discountCard", "DiscountCard");
            }

            //Insert customer
            _customerDataAccess.InsertDiscountCard(discountCard);

            //Updating customer code
            discountCard.CardNumber =
                StringHelper.Right("000000000" + discountCard.DiscountCardId, 9);
            UpdateDiscountCard(discountCard);
        }
Пример #17
0
 private DiscountCard GetSelectedCard()
 {
     if (cardsGrid.SelectedRows.Count == 1)
     {
         ExtendedCard ecard = cardsGrid.SelectedRows[0].DataBoundItem as ExtendedCard;
         DiscountCard card  = new DiscountCard();
         card.RecordId = ecard.CardId;
         card.Credit   = ecard.Credit;
         card.ClientId = ecard.ClientId;
         return(card);
     }
     else
     {
         return(null);
     }
 }
Пример #18
0
        public void Checkout_WithoutDiscountCard_DiscountCardDoesntApplyToNewSale()
        {
            var sale1        = new Sale();
            var discountCard = new DiscountCard(1000);
            var product      = new Product("A", 2000);

            sale1.Add(product);
            sale1.AddDiscountCard(discountCard);
            sale1.Checkout();
            var sale2 = new Sale();

            sale2.Add(product);

            Assert.Equal(3, discountCard.CurrentPercent());
            Assert.Equal(2000, sale2.Checkout());
            Assert.Equal(3, discountCard.CurrentPercent());
        }
Пример #19
0
        public void Checkout_WithDiscountCard_DiscountCardAddsOnlyUnitPriceToBalance()
        {
            var sale         = new Sale();
            var discountCard = new DiscountCard(1000);
            var product      = new Product("A", 1000, new VolumeDiscount(2000, 3));

            sale.Add(product);
            sale.Add(product);
            sale.Add(product);
            sale.Add(product);

            sale.AddDiscountCard(discountCard);

            Assert.Equal(1000, discountCard.Balance);
            Assert.Equal(2990, sale.Checkout());
            Assert.Equal(2000, discountCard.Balance);
        }
Пример #20
0
        public void UserWithSufficientAccount_GotCharged_AccountAndDiscountCardAmountsAlter(
            DiscountProgram discountProgram,
            Money price,
            Account accountBeforeCharge,
            Account accountAfterCharge,
            DiscountCard discountCardBeforeCharge,
            DiscountCard discountCardAfterCharge)
        {
            // Arrange
            var sut = new User(discountCardBeforeCharge, accountBeforeCharge);

            // Act
            sut.Charge(price, discountProgram);

            // Assert
            sut.DiscountCard.Should().NotBeNull().And.BeEquivalentTo(discountCardAfterCharge);
            sut.Account.Should().NotBeNull().And.BeEquivalentTo(accountAfterCharge);
        }
Пример #21
0
        public void AddCard(DiscountCardDTO dto)
        {
            Customer customer = Database.CustomerRepository.Get(dto.CustomerId);

            if (customer == null)
            {
                throw new ValidationException("Покупатель не найден", "");
            }

            DiscountCard card = new DiscountCard
            {
                Id   = dto.CustomerId,
                Code = dto.Code,
            };

            Database.DiscountCardRepository.Create(card);
            Database.Save();
        }
Пример #22
0
        public override bool OpenRecord(object primaryKey)
        {
            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            if (primaryKey != null)
            {
                int idCard = (int)primaryKey;
                card      = dg.Select(idCard);
                newRecord = false;
            }
            else
            {
                card      = new DiscountCard();
                newRecord = true;
            }
            BindData();
            return(true);
        }
Пример #23
0
        // добавим карту
        private void button1_Click(object sender, EventArgs e)
        {
            if (ci.getSelectedValue(cardGroup_comboBox1) == -1)
            {
                statusStrip1.Text = "Необходимо указать тип скидочной карты";
                return;
            }

            if (isEditMode)
            {
                currentCardForEditMode.idOwner = ci.getSelectedValue(owner_comboBox1);
                //    currentCardForEditMode.Number = cardNumber_textBox1.Text;
                currentCardForEditMode.idSeller            = admin.USER_ID;
                currentCardForEditMode.IdDiscountCardGroup = ci.getSelectedValue(cardGroup_comboBox1);
                admin.model.editDiscountCard(currentCardForEditMode);
                this.Close();
            }
            else
            {
                DiscountCard someCard = new DiscountCard
                {
                    idOwner             = ci.getSelectedValue(owner_comboBox1),
                    Number              = cardNumber_textBox1.Text,
                    Created             = assigned_dateTimePicker1.Value,
                    idSeller            = admin.USER_ID,
                    ValidUntil          = DateTime.Now.AddYears(100),
                    IsBlocked           = false,
                    SalePlace           = "",
                    IdDiscountCardGroup = ci.getSelectedValue(cardGroup_comboBox1)
                };

                bool isAdded = admin.model.assignDiscountCard(someCard);
                if (isAdded == false)
                {
                    MessageBox.Show("Не удалось добавить карту. Возможно, карта с таким номером уже выдана другому пилоту");
                }
                else
                {
                    this.Close();
                }
            }
        }
Пример #24
0
        public static void Update(DiscountCard discountCard)
        {
            var date = DateTime.Now;

            var document = XDocument.Load(Path);
            var element  = document.GetXElements("DiscountCards", "rec").First(el => el.GetXElementValue("CustomerId").ToGuid() == discountCard.CustomerId);

            DiscountCard.SetXmlValues(element, discountCard);
            File.WriteAllText(Path, document.ToString());

            if (SyncData.IsConnect)
            {
                using (var connection = ConnectionFactory.CreateConnection())
                    connection.Execute(UpdateQuery, new { discountCard.Points, date, discountCard.CustomerId });
            }

            var idx = DiscountCards.FindIndex(ds => ds.CustomerId == discountCard.CustomerId);

            DiscountCards[idx] = discountCard;
        }
Пример #25
0
        private void acceptButton_Click(object sender, EventArgs e)
        {
            Training t = new Training();

            t.LockerId  = lockers[comboLocker.SelectedIndex].RecordId;
            t.ClientId  = clients[comboClient.SelectedIndex].RecordId;
            t.TrainerId = trainers[comboTrainer.SelectedIndex].RecordId;
            t.ToGender  = clients[comboClient.SelectedIndex].Gender;
            t.TimeFrom  = DateTime.Now;

            ClientFactory          clientFactory = new ClientFactory();
            ClientGateway <Client> cg            = (ClientGateway <Client>)clientFactory.GetClient();
            Client c = cg.Select(t.ClientId);

            DiscountFactory discountFactory   = new DiscountFactory();
            DiscountGateway <DiscountCard> dg = (DiscountGateway <DiscountCard>)discountFactory.GetCard();

            DiscountCard card = new DiscountCard();

            if (c.CardId != null)
            {
                int toSetId = c.CardId ?? 0;
                card = dg.Select(toSetId);
            }
            TrainingFactory            trainingFactory = new TrainingFactory();
            TrainingGateway <Training> tg = (TrainingGateway <Training>)trainingFactory.GetTraining();

            tg.Insert(t);

            if (card != null && card.Credit > 0)
            {
                Forms.ChangeCredit form = new Forms.ChangeCredit();
                form.ShowDialog();
            }
            else
            {
                MessageBox.Show("Training was added successfully but client " + c.Name + " " + c.Surname + " has no credit on card!", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            }
            this.Dispose();
        }
Пример #26
0
        public Client(double PurchaseValue, double Turnover, int TypeOfCard)
        {
            this.PurchaseValue = PurchaseValue;
            switch (TypeOfCard)
            {
            case 1:
                this.card = new BronzeCard(Turnover);
                break;

            case 2:
                this.card = new SilverCard(Turnover);
                break;

            case 3:
                this.card = new GoldCard(Turnover);
                break;

            default:
                break;
            }
            this.Discount = PurchaseValue * (card.InitialDiscount / 100);
        }
        public async Task <ActionResult <DiscountCard> > IssueLoyaltyCardForClient(DiscountCard discountCard)
        {
            if (discountCard.ClientId == 0)
            {
                return(BadRequest("Please specify Id for an existing client"));
            }

            var client = await _context.Clients.SingleOrDefaultAsync(c => c.Id == discountCard.ClientId);

            if (client is null)
            {
                return(BadRequest("Please specify Id for an existing client"));
            }

            client.DiscountCards.Add(discountCard);
            _context.Entry(client).State = EntityState.Modified;

            _context.LoyaltyCards.Add(discountCard);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("IssueLoyaltyCardForClient", new { id = discountCard.Number }, discountCard));
        }
Пример #28
0
        private Collection <T> Read(SqlDataReader reader)
        {
            Collection <T> cards = new Collection <T>();

            while (reader.Read())
            {
                DiscountCard card = new DiscountCard();
                int          i    = -1;
                card.RecordId = reader.GetInt32(++i);

                if (!reader.IsDBNull(++i))
                {
                    card.ClientId = reader.GetInt32(i);
                }
                if (!reader.IsDBNull(++i))
                {
                    card.Credit = reader.GetDecimal(i);
                }

                cards.Add((T)card);
            }
            return(cards);
        }
Пример #29
0
        // edit mode
        public Discount_Card_Add(AdminControl ad, int idCard)
        {
            InitializeComponent();

            this.Text = "Редактирование скидочной карты";
            admin     = ad;
            fillDiscountCardTypies();


            DiscountCard someCard = admin.model.getAllDiscountCards().Where(m => m.Id == idCard).Take(1).SingleOrDefault();

            if (someCard == null)
            {
                return;
            }

            fillOwners(true, Convert.ToInt32(someCard.idOwner));

            currentCardForEditMode = someCard;

            isEditMode = true;
            cardNumber_textBox1.Enabled = false;

            cardNumber_textBox1.Text = someCard.Number;

            if (someCard.idOwner != null)
            {
                ci.selectComboBoxValueById(owner_comboBox1,
                                           Convert.ToInt32(someCard.idOwner));
            }

            if (someCard.IdDiscountCardGroup != null)
            {
                ci.selectComboBoxValueById(cardGroup_comboBox1,
                                           Convert.ToInt32(someCard.IdDiscountCardGroup));
            }
        }
Пример #30
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };

                var discountCard = new DiscountCard {
                    CardType = null
                };
                var moneyAccount = new MoneyAccount {
                    Balance = 0, ApplicationUser = user, DiscountCard = discountCard
                };
                user.MoneyAccount = moneyAccount;

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }