Пример #1
0
        private void OnLinkDiscountCardCommandExecuted()
        {
            var firstDiscount = _dc.CumulativeDiscounts
                                .OrderBy(x => x.Percent)
                                .FirstOrDefault();

            if (firstDiscount != null)
            {
                _discountCard = new Models.DiscountCard()
                {
                    Code               = Models.DiscountCard.GenerateCode(),
                    DiscountPercent    = firstDiscount.Percent,
                    MaxDiscount        = firstDiscount.MaxDiscount,
                    MinDiscount        = firstDiscount.MinDiscount,
                    DiscountTypeID     = (int)Enums.DiscountType.Cumulative,
                    TotalPurchaseValue = 0
                };
                _customer.DiscountCard = _discountCard;
                DiscountCardEnabled    = true;
                _dc.SaveChanges();
                RaisePropertiesChanged(BindGroupAttribute.GetPropertiesOfGroup(this.GetType(), "DiscountCard").Select(x => x.Name).ToArray());
            }
            else
            {
                MessageService.Show("Нельзя выполнить данную операцию, т.к. не заполнен справочник скидок!\nЗаполните справочник скидок и повторите попытку.", "Отсутствуют данные в справочнике", MessageBoxButton.OK, MessageBoxImage.Error);
            };
        }
Пример #2
0
        private void OnUnlinkDiscountCardCommandExecuted()
        {
            DiscountCardEnabled = false;
            var cardID   = _discountCard.ID;
            var cardCode = _discountCard.Code;

            _discountCard          = null;
            _customer.DiscountCard = null;

            RaisePropertiesChanged(BindGroupAttribute.GetPropertiesOfGroup(this.GetType(), "DiscountCard").Select(x => x.Name).ToArray());
            _dc.SaveChanges();

            if (!_dc.Customers.Any(x => x.DiscountCardID == cardID) &&
                MessageService.Show(String.Format("Карта с кодом \"{0}\" не принадлежит ни одному клиенту, удалить карту из системы?", cardCode), "Подтвердите удаление картф", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                var card = _dc.DiscountCards.Single(x => x.ID == cardID);
                _dc.DiscountCards.Remove(card);
                _dc.SaveChanges();
            }
        }