コード例 #1
0
        public async Task <ValidationResult> Insert(List <Bill> billList)
        {
            BillValidation   billValidation   = new BillValidation();
            ValidationResult validationResult = new ValidationResult();
            Bill             billReturn       = new Bill();

            foreach (var bill in billList)
            {
                validationResult = billValidation.Validate(bill);

                if (validationResult.IsValid)
                {
                    billReturn = await Task.Run(() => _billRepository.Add(bill));
                }
            }

            return(validationResult);
        }
コード例 #2
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            try
            {
                subscriber.Name     = txtFirstName.Text;
                subscriber.LastName = txtLastName.Text;
                subscriber.Address  = txtFullAddress.Text;

                subscriber.Birthday = dtPickerBirthdate.Value;

                subscriber.PersonalNo     = txtPersonalNumber.Text;
                subscriber.Email          = txtEmail.Text;
                subscriber.PhoneNo        = txtPhoneNumber.Text;
                subscriber.InsDate        = DateTime.Parse(txtFromDate.Text);
                subscriber.ExpirationDate = DateTime.Parse(txtTillDate.Text);

                subscriber.IsActive = true;

                subscriber.InsBy = FormLoggedUser.Id;

                if (radioMale.Checked)
                {
                    subscriber.Gender = 'M';
                }
                else
                {
                    subscriber.Gender = 'F';
                }

                SubscriberValidation subscriberValidator = new SubscriberValidation();
                subscriberValidator.subscriber = subscriber;
                subscriberValidator.ValidateSubscriber();
                ValidationResult results = subscriberValidator.Validate(subscriber);

                if (results.IsValid == false)
                {
                    foreach (ValidationFailure failure in results.Errors)
                    {
                        MessageBox.Show($"{failure.ErrorMessage}", "Error Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }

                else
                {
                    subscriberBLL.Add(subscriber);
                    //MessageBox.Show("The subscriber is registered successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    subscriberBLL.SubscriberRegisterdEmail(subscriber);

                    #region BILL///////////////////////////////////////////////////////////////////////////////////////////
                    bill.BillingDate      = DateTime.Now;
                    bill.RegistrationDate = subscriber.InsDate;
                    bill.ExpirationDate   = subscriber.ExpirationDate;

                    if (subscriber.ExpirationDate.Month == subscriber.InsDate.AddMonths(1).Month)
                    {
                        bill.Price = 10;//10euro per Muaj
                    }

                    if (subscriber.ExpirationDate.Year == subscriber.InsDate.AddYears(1).Year)
                    {
                        bill.Price = 100;//100euro per Vit
                    }

                    bill.BillTypeId = 1;
                    bill.IsActive   = true;
                    bill.InsBy      = FormLoggedUser.Id;

                    BillValidation billValidator = new BillValidation();
                    billValidator.bill = bill;
                    billValidator.ValidateBill();
                    ValidationResult resultsBill = billValidator.Validate(bill);

                    if (resultsBill.IsValid == false)
                    {
                        foreach (ValidationFailure failure in resultsBill.Errors)
                        {
                            MessageBox.Show($"{failure.ErrorMessage}", "Error Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        bill.SubscriberId = subscriberBLL.MaxSubscriberId();
                        billBLL.Add(bill);
                        MessageBox.Show("The Subscriber is registered successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        notification.Message  = $"Member {subscriber.Name} {subscriber.LastName} is registered from date {subscriber.InsDate} till {subscriber.ExpirationDate}";
                        notification.Date     = DateTime.Now;
                        notification.Category = "Subscriber Notification";

                        notificationBLL.Add(notification);
                    }



                    #endregion
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
        private void btnUpdateMemberSubscription_Click(object sender, EventArgs e)
        {
            try
            {
                subscriber = subscriberBLL.Get(int.Parse(txtMemberID.Text));

                subscriber.UpdDate        = DateTime.Parse(txtFromDate.Text);
                subscriber.ExpirationDate = DateTime.Parse(txtTillDate.Text);
                subscriber.IsActive       = true;
                subscriber.UpdBy          = FormLoggedUser.Id;

                SubscriberValidation subscriberValidator = new SubscriberValidation();
                subscriberValidator.subscriber = subscriber;
                subscriberValidator.ValidateSubscriber();
                ValidationResult results = subscriberValidator.Validate(subscriber);

                if (results.IsValid == false)
                {
                    foreach (ValidationFailure failure in results.Errors)
                    {
                        MessageBox.Show($"{failure.ErrorMessage}", "Error Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    subscriberBLL.Update(subscriber);

                    #region BILL///////////////////////////////////////////
                    bill.BillingDate      = DateTime.Now;
                    bill.RegistrationDate = DateTime.Parse(txtFromDate.Text);
                    bill.ExpirationDate   = DateTime.Parse(txtTillDate.Text);

                    if (bill.ExpirationDate.Month == bill.RegistrationDate.AddMonths(1).Month)
                    {
                        bill.Price = 10;//10euro per Muaj
                    }

                    if (bill.ExpirationDate.Year == bill.RegistrationDate.AddYears(1).Year)
                    {
                        bill.Price = 100;//100euro per Vit
                    }

                    bill.BillTypeId = 1;
                    bill.IsActive   = true;
                    bill.InsBy      = FormLoggedUser.Id;

                    BillValidation billValidator = new BillValidation();
                    billValidator.bill = bill;
                    billValidator.ValidateBill();
                    ValidationResult resultsBill = billValidator.Validate(bill);

                    if (resultsBill.IsValid == false)
                    {
                        foreach (ValidationFailure failure in resultsBill.Errors)
                        {
                            MessageBox.Show($"{failure.ErrorMessage}", "Error Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        bill.SubscriberId = int.Parse(txtMemberID.Text);
                        billBLL.Add(bill);
                        MessageBox.Show("The subscription was successfully updated!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        CookieSubscriber.ID               = int.Parse(txtMemberID.Text);
                        CookieSubscriber.FullName         = subscriber.Name + " " + subscriber.LastName;
                        CookieSubscriber.PersonalNumber   = subscriber.PersonalNo;
                        CookieSubscriber.SubscriptionPlan = subscriptionPlanVariable;
                        CookieSubscriber.BillingDate      = bill.BillingDate;
                        CookieSubscriber.ExpirationDate   = subscriber.ExpirationDate;
                        CookieSubscriber.Price            = bill.Price;
                        CookieSubscriber.Cashier          = FormLoggedUser.Name + "\t " + FormLoggedUser.LastName;

                        BillingAddMember billingAddMember = new BillingAddMember();
                        billingAddMember.ShowDialog();
                    }
                    #endregion
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }