Example #1
0
        private async void createComboButton_Click(object sender, EventArgs e)
        {
            string comboName = tbComboName.Text;

            bool isValid = true;

            if (string.IsNullOrWhiteSpace(comboName))
            {
                errorProvider.SetError(tbComboName, "Bat buoc");
                isValid = false;
            }
            else
            {
                errorProvider.SetError(tbComboName, null);
            }

            if (discountPercentNumber.Value < 0)
            {
                errorProvider.SetError(discountPercentNumber, "Ko hop le");
                isValid = false;
            }
            else
            {
                errorProvider.SetError(discountPercentNumber, null);
            }

            if (!isValid)
            {
                return;
            }

            List <int> productIDs = new List <int>();

            foreach (Product item in products)
            {
                productIDs.Add(item.Id);
            }


            var res = await ComboController.CreateCombo(
                new CreateComboDTO
            {
                ComboName       = comboName,
                OriginalPrice   = calculateOriginalPrice().ToString(),
                Price           = calculatePrice().ToString(),
                DiscountPercent = Convert.ToInt32(discountPercentNumber.Value),
                ProductIds      = productIDs
            });

            if (res == null)
            {
                return;
            }
            if (!res.IsSuccess)
            {
                Notification.Error(HandleError <ComboErrorMessage> .GetErrorString(res.Messages));
                return;
            }

            Notification.Success("Success");

            _comboListPage.renderCombos();

            this.Close();
        }
        private async void updateComboButton_Click(object sender, EventArgs e)
        {
            string comboName = tbComboName.Text;

            bool isValid = true;

            if (string.IsNullOrWhiteSpace(comboName))
            {
                errorProvider.SetError(tbComboName, "Bat buoc");
                isValid = false;
            }
            else
            {
                errorProvider.SetError(tbComboName, null);
            }

            if (discountPercentNumber.Value < 0)
            {
                errorProvider.SetError(discountPercentNumber, "Ko hop le");
                isValid = false;
            }
            else
            {
                errorProvider.SetError(discountPercentNumber, null);
            }

            if (!isValid)
            {
                return;
            }

            decimal originalPrice = 0;

            foreach (Product item in combo.products)
            {
                originalPrice += item.Price;
            }


            var res = await ComboController.UpdateCombo(
                combo.Id,
                new UpdateComboDTO
            {
                ComboName          = comboName,
                OriginalPrice      = originalPrice.ToString(),
                Price              = (originalPrice - (originalPrice * discountPercentNumber.Value / 100)).ToString(),
                DiscountPercent    = Convert.ToInt32(discountPercentNumber.Value),
                DeletedProductIds  = deletedProductIds,
                InsertedProductIds = insertedProductIds
            });

            if (res == null)
            {
                return;
            }
            if (!res.IsSuccess)
            {
                Notification.Error(HandleError <ComboErrorMessage> .GetErrorString(res.Messages));
                return;
            }

            Notification.Success("Success");

            deletedProductIds  = new List <int>();
            insertedProductIds = new List <int>();

            _comboListPage.renderCombos();

            this.renderCombo(true);
        }