예제 #1
0
        public void AddingValidCustomer()
        {
            var defaultCustomer = TestUtils.DefaultValidCustomer();

            var result = _customerService.AddCustomer(
                defaultCustomer.Firstname,
                defaultCustomer.Surname,
                defaultCustomer.EmailAddress,
                defaultCustomer.DateOfBirth,
                defaultCustomer.Company.Id
                );

            Assert.IsTrue(result);

            _creditServiceWrapperMock.Verify(x => x.HasCreditLimit(It.IsAny <Customer>()), Times.Exactly(1));

            _creditServiceWrapperMock.Verify(x => x.CreditLimit(It.IsAny <Customer>()), Times.Exactly(1));

            _companyRepositoryMock.Verify(x => x.GetById(It.IsAny <int>()), Times.Exactly(1));

            _customerDataAccessMock.Verify(x => x.AddCustomer(It.Is <Customer>(y =>
                                                                               y.Firstname == defaultCustomer.Firstname &&
                                                                               y.Surname == defaultCustomer.Surname &&
                                                                               y.EmailAddress == defaultCustomer.EmailAddress &&
                                                                               y.DateOfBirth == defaultCustomer.DateOfBirth &&
                                                                               y.Company.Id == defaultCustomer.Company.Id &&
                                                                               y.HasCreditLimit == true &&
                                                                               y.CreditLimit == 2000
                                                                               )), Times.Exactly(1));
        }
예제 #2
0
        public void AddCustomer_ValidatesRequest()
        {
            //arrange
            var request = _fixture.Create <AddCustomerRequest>();

            //act
            _customerService.AddCustomer(request);

            //assert
            _validator.Verify(x => x.ValidateRequest(request), Times.Once);
        }
예제 #3
0
 /// <summary>
 ///     AddCustomer by passing CustomerModel
 /// </summary>
 /// <param name="parameter">CustomerModel</param>
 public void Execute(object parameter = null)
 {
     if (parameter?.GetType() == typeof(CustomerModel))
     {
         _customerService.AddCustomer((CustomerModel)parameter);
         _customerModel = (CustomerModel)parameter;
     }
     else if (!(_customerModel is null))
     {
         _customerService.AddCustomer(_customerModel);
     }
 }
        public void Should_AddCustomer_ReturnFalse_WhenTheCompanyCreditLimitIsLessThan500()
        {
            // Arrange
            SetupCreditLimit(100);

            // Act
            var result = _subject.AddCustomer("FName", "sName", "*****@*****.**", DateTime.Now.AddYears(-20), 1);

            // Assert
            result.Should().BeFalse();
            _customerRepositoryMock.Verify(x => x.SaveCustomer(It.IsAny <Customer>()), Times.Never);
        }
예제 #5
0
        public async Task CustomerService_AddCustomer_Repo_Exception_Test()
        {
            //Arrange
            _customerRepoMock.Setup(x => x.AddCustomer(It.IsAny <Customer>())).ThrowsAsync(new Exception());

            //Act
            var res = await _custService.AddCustomer(new Customer());

            //Assert
            Assert.IsFalse(res.ReturnObject);
            Assert.AreEqual(ErrorCodes.OTHER, res.ErrorCode);
            Assert.AreEqual(ErrorCodes.OTHER.GetDescription(), res.Message);
            _customerRepoMock.Verify(x => x.AddCustomer(It.IsAny <Customer>()), Times.Once);
        }
예제 #6
0
 public ActionResult CreateCustomerStep3(CustomerBankPaymentDetailsVM mCustomer)
 {
     if (ModelState.IsValid)
     {
         var customer = TempCustomer;
         if (TryUpdateModel(customer))
         {
             if (ExecuteRepositoryAction(() => { _customerService.AddCustomer(customer); _customerService.CommitChanges(); }))
             {
                 return(View("Edit", customer));
             }
         }
     }
     return(View(mCustomer));
 }
예제 #7
0
        public bool AddCustomer(Customer customer)
        {
            //check the validity of the input
            if (true)
            {
                try
                {
                    //instantiate CustomerService class
                    CustomerService cs = new CustomerService();

                    //Call AddCustomer method to fetch all Food Items
                    bool isAdded = cs.AddCustomer(customer);

                    //return the response
                    return(isAdded);
                }
                catch (CustomerException)
                {
                    //rethrow
                    throw;
                }
            }

            else
            {
                //throw user defined exception object
                throw new CustomerException("The entered details to fetch the Customers are not valid");
            }
        }
예제 #8
0
        public void scenarios2()
        {
            var customerService = new CustomerService(new CustomerRepository());
            var customer        = new Customer()
            {
                Discounts = new List <Discount> {
                    new Discount {
                        ServiceId = "B",
                        Start     = new DateTime(2018, 01, 01),
                        Percent   = 30
                    },
                    new Discount {
                        ServiceId = "C",
                        Start     = new DateTime(2018, 01, 01),
                        Percent   = 30
                    }
                },
                Services = new List <IService> {
                    new ServiceB(new DateTime(2018, 01, 01)),
                    new ServiceC(new DateTime(2018, 01, 01))
                },
                FreeDays = 200
            };

            customerService.AddCustomer(customer);

            var sut    = new PricingService(customerService);
            var result = sut.GetPrices(customer.CustomerId, customer.Services.First().StartDate, new DateTime(2019, 10, 01));

            Assert.That(result, Is.EqualTo(175.504M));
        }
예제 #9
0
        public void ShouldReturnFalseWhenSurnameIsEmptyOrNull(string surname)
        {
            CustomerService customerService = new CustomerService();
            var             result          = customerService.AddCustomer("firstname", surname, "*****@*****.**", new DateTime(2000, 01, 01), 1);

            Assert.False(result);
        }
예제 #10
0
        public void ShouldReturnFalseWhenEmailIsInvalid(string email)
        {
            CustomerService customerService = new CustomerService();
            var             result          = customerService.AddCustomer("firstname", "surname", email, new DateTime(2000, 01, 01), 1);

            Assert.False(result);
        }
예제 #11
0
        public void AddCustomer_GivenValidInputs_ReturnsTrue()
        {
            var mockCompanyRepository = new Mock <ICompanyRepository>();
            var mockCompany           = new Company
            {
                Classification = Classification.Gold,
                Id             = 4,
                Name           = "The Company"
            };

            CustomerDataAccess.CustomerDataAccessor = NSubstitute.Substitute.For <ICustomerDataAccess>();
            var mockCustomerDataAccess = new Mock <ICustomerDataAccess>();

            CustomerDataAccess.CustomerDataAccessor = mockCustomerDataAccess.Object;

            bool expected = true;

            mockCompanyRepository.Setup(x => x.GetById(4)).Returns(mockCompany);

            CustomerService customerService = new CustomerService(mockCompanyRepository.Object);

            var actual = customerService.AddCustomer("Joe", "Bloggs", "*****@*****.**", new DateTime(1980, 3, 27), 4);

            Assert.AreEqual(expected, actual);
        }
예제 #12
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User created a new account with password.");

                    var customerService = new CustomerService();
                    customerService.AddCustomer(user.Id, user.Email);

                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #13
0
        public ActionResult Callback(string code, string state)
        {
            if (string.IsNullOrEmpty(code) || state != WeixinData.Token)
            {
                return(Content("验证授权失败!"));
            }
            //通过,用code换取access_token
            OAuthAccessTokenResult result = null;

            try
            {
                result = OAuthApi.GetAccessToken(Comm.WeixinData.AppId, Comm.WeixinData.AppSecret, code);
                if (result.errcode != ReturnCode.请求成功)
                {
                    return(Content("错误:" + result.errmsg));
                }
                OAuthUserInfo   userInfo = OAuthApi.GetUserInfo(result.access_token, result.openid);
                CustomerService cs       = new CustomerService();
                var             customer = cs.AddCustomer(userInfo);
                if (customer.IsManager)
                {
                    Session["user"] = customer;
                    return(RedirectToAction("index", "admin"));
                }
                ViewBag.msg = "登录失败";

                return(View("index"));
            }
            catch (Exception ex)
            {
                return(Content(ex.Message));
            }
        }
예제 #14
0
        public void CheckCustomerServiceAddCustomer()
        {
            customerService.AddCustomer(customer);
            var result = customerService.SaveChangesAsync();

            Assert.IsTrue(result);
        }
예제 #15
0
        private void btnAddCustomer_Click(object sender, RoutedEventArgs e)
        {
            Customer cx = new Customer()
            {
                FirstName = txtFname.Text,
                LastName  = txtLName.Text,
                Gender    = (cmbGender.SelectedIndex == 0) ? "M" : ((cmbGender.SelectedIndex == 1) ? "F" : null),
                Phone     = txtPhone.Text,
                Email     = txtEmail.Text
            };

            int result = cs.AddCustomer(cx);

            btnResetAddForm_Click(sender, null);

            if (result != -1) // Success
            {
                // Reload the Datagrid Data from DB
                ManageCustomers.mv.Customers = cs.GetCustomers();
                // Atempt to Reload the Datagrid without a trip to DB (did not work):
                // cx.Id = result;
                // BookFlights.mv.Customers.Add(cx);
                MessageBox.Show($"Customer created with ID: {result.ToString()}",
                                "Success",
                                MessageBoxButton.OK,
                                MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show($"Something went wrong.",
                                "Error",
                                MessageBoxButton.OK,
                                MessageBoxImage.Error);
            }
        }
예제 #16
0
        public void SaveCustomerTest()
        {
            ICustomerService customerService = new CustomerService(GetMockCustomerDataAccess(), GetMockCustomerbuilder());
            var actualResult = customerService.AddCustomer(customer.Firstname, customer.Surname, customer.EmailAddress, dob, mockCompany.Id);

            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(true, actualResult, "Invalid Save");
        }
예제 #17
0
 protected void btnCustSave_Click(object sender, EventArgs e)
 {
     CustomerService.AddCustomer(Convert.ToString(ViewState["LetterNo"]),
                                 txtCustName.Text,
                                 "I",
                                 dtpCustBirthDate.SelectedDate,
                                 rblCustGender.SelectedValue,
                                 String.IsNullOrEmpty(ddlCustJobPosition.SelectedValue) ? 0 : Convert.ToInt32(ddlCustJobPosition.SelectedValue),
                                 txtCustEmail.Text,
                                 txtCustAddress.Text,
                                 txtCustZipCode.Text,
                                 txtCustWebsite.Text,
                                 txtInformationSource.Text,
                                 new Dictionary <int, string>()
     {
         { 1, txtCustCellPhone1.Text }, { 2, txtCustCellPhone2.Text }
     },
                                 new Dictionary <int, string>()
     {
         { 1, txtCustSocialMediaNetwork1.Text },
         { 2, txtCustSocialMediaNetwork2.Text }
     },
                                 new Dictionary <int, string>()
     {
         { 1, txtCustWorkPhone1.Text }, { 2, txtCustWorkPhone2.Text }
     });
     ;
     RadGridParticipants.DataBind();
 }
예제 #18
0
        public void AddCustomer_HasNoAtSignInTheEmailAndCreditLimitZero_ReturnsFalse()
        {
            // Arrange
            string   firstName    = String.Empty;
            string   surname      = "Csibi";
            string   emailAddress = "norbertcsibitechgmail.com";
            DateTime dateOfBirth  = new DateTime(1992, 11, 21);
            int      companyId    = 1;

            var company = new Company {
                Id = 1, Name = "Norbert Ltd", Classification = Classification.Gold
            };

            var mockCompanyRepository     = new Mock <ICompanyRepository>();
            var mockCustomerCreditService = new Mock <ICustomerCreditService>();

            var mockCustomerService = new Mock <ICustomerService>();

            mockCompanyRepository.Setup(x => x.GetById(It.IsAny <int>()))
            .Returns(company);



            var customerService = new CustomerService(mockCompanyRepository.Object, mockCustomerCreditService.Object);

            // Act
            var result = customerService.AddCustomer(firstName, surname, emailAddress, dateOfBirth, companyId);

            // Assert

            Assert.IsFalse(result);
        }
        public IActionResult Register(CustomerModels newCustomer)
        {//works only if no customer validation lol
            try
            {
                CustomerModels customer = new CustomerModels()
                {
                    Username = newCustomer.Username,
                    email    = newCustomer.email
                };

                /* List<CustomerModels> getCustomersTask = _customerService.GetAllCustomers();
                 * foreach (var h in getCustomersTask)
                 * {
                 *   if (newCustomer.Username.Equals(h.Username))
                 *   {
                 *       throw new Exception("Sorry this username is already taken");
                 *   }
                 *   else
                 *   {
                 *       if (newCustomer.email.Equals(h.email))
                 *       {
                 *           throw new Exception("Sorry this email is already registered");
                 *       }
                 *   }
                 * } */
                _customerService.AddCustomer(newCustomer);
                CartsModel cart = new CartsModel();
                cart.CustomerID = newCustomer.ID;
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
예제 #20
0
        public void scenarios1()
        {
            var customerService = new CustomerService(new CustomerRepository());
            var customer        = new Customer()
            {
                Discounts = new List <Discount> {
                    new Discount {
                        ServiceId = "c",
                        Start     = new DateTime(2019, 09, 22),
                        End       = new DateTime(2019, 09, 24),
                        Percent   = 20
                    }
                },
                Services = new List <IService> {
                    new ServiceA(new DateTime(2019, 09, 20)),
                    new ServiceC(new DateTime(2019, 09, 20))
                }
            };

            customerService.AddCustomer(customer);

            var sut    = new PricingService(customerService);
            var result = sut.GetPrices(customer.CustomerId, new DateTime(2019, 09, 20), new DateTime(2019, 10, 01));

            Assert.That(result, Is.EqualTo(6.16M));
        }
예제 #21
0
        public void TestAddCustomer_WithCustomerIsNotNull_ShouldHaveNewCustomer()
        {
            //Arrange
            Customers savedCustomer = null;
            var       customerData  = new Customers
            {
                CustomerName = "test123",
                ContactEmail = "*****@*****.**"
            };
            var mockCustomerRepository = new Mock <ICustomerRepository>();

            mockCustomerRepository.Setup(x => x.SaveCustomer(customerData)).Callback <Customers>(x => savedCustomer = x);
            var mockUnitOfWork = new Mock <IUnitOfWork>();

            mockUnitOfWork.Setup(x => x.SaveChanges());
            var customerService = new CustomerService(mockCustomerRepository.Object, null, mockUnitOfWork.Object);


            //Act
            customerService.AddCustomer(customerData);

            //Assert
            mockCustomerRepository.Verify(x => x.SaveCustomer(customerData), Times.Once);
            mockUnitOfWork.Verify(x => x.SaveChanges(), Times.Once);
            Assert.AreEqual(customerData.CustomerName, savedCustomer.CustomerName);
            Assert.AreEqual(customerData.ContactEmail, savedCustomer.ContactEmail);
        }
예제 #22
0
        public void CheckCustomerIfExistAfterAdd()
        {
            //Arrange
            NewCustomerVm customerToAdd = new NewCustomerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit"
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var customerService = new CustomerService(new CustomerRepository(context), mapper);
                var result          = customerService.AddCustomer(customerToAdd);

                //Assert
                context.Customers.FirstOrDefaultAsync(e => e.Id == result).Should().NotBeNull();
            }
        }
예제 #23
0
        public void DeletedCustomerShoundNotExistInDatabase()
        {
            //Arrange
            NewCustomerVm customerToAdd = new NewCustomerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit",
                customerContactInfos = null
            };

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            using (var context = new Context(options))
            {
                //Act
                var customerService = new CustomerService(new CustomerRepository(context), mapper);
                var result          = customerService.AddCustomer(customerToAdd);
                customerService.DeleteCustomer(1);
                var deletedCustomer = customerService.GetCustomerDetails(1);

                //Assert
                deletedCustomer.Should().BeNull();
            }
        }
        public void AddCustomer_Success_NoCreditLimit()
        {
            TestCustomerRepository    customerRepository    = new TestCustomerRepository();
            TestCompanyRepository     companyRepository     = new TestCompanyRepository();
            TestCustomerCreditService customerCreditService = new TestCustomerCreditService();

            Customer customer = new Customer()
            {
                Firstname    = "John",
                Surname      = "Doe",
                DateOfBirth  = DateTime.Now.AddYears(-22),
                EmailAddress = "*****@*****.**",
            };

            CustomerService customerService = new CustomerService(companyRepository, customerRepository, customerCreditService);

            customerService.AddCustomer(customer.Firstname, customer.Surname, customer.EmailAddress, customer.DateOfBirth, 1);

            var addedCustomer = customerRepository.GetLastAddedCustomer();

            Assert.AreEqual(customer.Firstname, addedCustomer.Firstname);
            Assert.AreEqual(customer.Surname, addedCustomer.Surname);
            Assert.AreEqual(customer.EmailAddress, addedCustomer.EmailAddress);
            Assert.AreEqual(customer.DateOfBirth, addedCustomer.DateOfBirth);
            Assert.IsFalse(addedCustomer.HasCreditLimit);
        }
예제 #25
0
        public void CheckCustomerToEditDetailsAreEqualLikeModel()
        {
            //Arrange
            NewCustomerVm customerToAdd = new NewCustomerVm()
            {
                Id   = 1,
                Name = "test",
                NIP  = "Unit",
                customerContactInfos = null
            };

            var config = new MapperConfiguration(c =>
            {
                c.AddProfile(new MappingProfile());
            });
            var mapper = config.CreateMapper();

            var options = new DbContextOptionsBuilder <Context>()
                          .UseInMemoryDatabase("UsersDirectoryMVC")
                          .Options;


            using (var context = new Context(options))
            {
                //Act
                var customerService = new CustomerService(new CustomerRepository(context), mapper);
                customerService.AddCustomer(customerToAdd);
                var result = customerService.GetCustomerForEdit(1);

                //Assert
                result.Should().NotBeNull();
                result.Should().Equals(customerToAdd);
                context.Customers.FirstOrDefaultAsync(e => e.Id == result.Id).Should().NotBeNull();
            }
        }
예제 #26
0
 public ActionResult Create(CustomerModel customerModel)
 {
     customerModel.CreatedDate = DateTime.Today;
     customerModel.UpdatedDate = null;
     CustomerServices.AddCustomer(customerModel);
     return(RedirectToAction("Index"));
 }
        private void Save()
        {
            using (var transaction = new TransactionScope()) {
                foreach (var item in customers)
                {
                    if (item.CrudType == BookCoreLibrary.Core.CRUDType.INSERT)
                    {
                        item.Idx = viewModel.AddCustomer(item);

                        if (item.Idx > 0)
                        {
                            item.CrudType = BookCoreLibrary.Core.CRUDType.NONE;
                        }
                    }
                    else if (item.CrudType == BookCoreLibrary.Core.CRUDType.MODIFY)
                    {
                        if (viewModel.ModifyCustomer(item))
                        {
                            item.CrudType = BookCoreLibrary.Core.CRUDType.NONE;
                        }
                    }
                }

                transaction.Complete();
            }
        }
예제 #28
0
        public void ShouldReturnFalseWhenCustomerIsUnder21()
        {
            var             dateOfBirth     = DateTime.Now.AddYears(-20);
            CustomerService customerService = new CustomerService();
            var             result          = customerService.AddCustomer("firstname", "surname", "*****@*****.**", dateOfBirth, 1);

            Assert.False(result);
        }
        public void When_His_First_Name_Is_Null_Or_Empty_Then_Return_False(string firstName)
        {
            var customerInfo = new Customer()
            {
                Firstname    = firstName,
                Surname      = "Doan",
                EmailAddress = "*****@*****.**",
                DateOfBirth  = _dateOfBirth,
                CompanyId    = 1
            };
            var result = _mockCustomerService.AddCustomer(customerInfo);

            Assert.AreEqual(false, result);
        }
예제 #30
0
 public IActionResult AddCustomer([FromForm] Customer customer)
 {
     if (ModelState.IsValid)
     {
         _cs.AddCustomer(customer);
         return(RedirectToAction(nameof(Index)));
     }
     return(View());
 }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (validator1.Validate() && ValidateData())
     {
         if (customer != null && customer.Id > 0)
         {
             Employee emp = null;
             int old_saler_id = (int)customer.SalerId;
             if (cmbSaler.SelectedValue != null)
             {
                 emp = salers.Single(x => x.Id == (int)cmbSaler.SelectedValue);
                 customer.Employee = emp;
             }
             if (emp == null || emp.Id != old_saler_id)
             {
                 DialogResult dl = MessageBox.Show("Chuyến nhân viên của khách hàng và đồng ý chuyển hoa hồng cho nhân viên mới?", "Thông tin!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                 if (dl == DialogResult.Yes)
                 {
                     EmployeeLogService els = new EmployeeLogService();
                     els.MoveEmployeeLogOfCustomer(customer.Id, old_saler_id, emp.Id);
                 }
             }
             customer.Description = txtDescription.Text;
             customer.CustCode = txtCode.Text;
             customer.Address = txtAddress.Text;
             customer.BankAcc = txtBankAcc.Text;
             customer.BankName = txtBankName.Text;
             customer.ContactPersonEmail = txtContactPersonEmail.Text;
             customer.ContactPerson = txtContactPersonName.Text;
             customer.ContactPersonPhone = txtContactPersonPhone.Text;
             customer.Email = txtEmail.Text;
             customer.Fax = txtFax.Text;
             customer.Phone = txtPhoneNumber.Text;
             customer.CustomerName = txtName.Text;
             customer.FavoriteProduct = txtFavoriteProduct.Text;
             CustomerService customerService = new CustomerService();
             bool result = customerService.UpdateCustomer(customer);
             if (result)
             {
                 MessageBox.Show("Khách hàng được cập nhật thành công");
                 if (this.CallFromUserControll != null && this.CallFromUserControll is CustomerList)
                 {
                     ((CustomerList)this.CallFromUserControll).loadCustomerList();
                 }
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             customer = new Customer
             {
                 Description = txtDescription.Text,
                 CustCode = txtCode.Text,
                 Address = txtAddress.Text,
                 BankAcc = txtBankAcc.Text,
                 BankName = txtBankName.Text,
                 ContactPerson = txtContactPersonName.Text,
                 ContactPersonEmail = txtContactPersonEmail.Text,
                 ContactPersonPhone = txtContactPersonPhone.Text,
                 Email = txtEmail.Text,
                 Fax = txtFax.Text,
                 Phone = txtPhoneNumber.Text,
                 CustomerName = txtName.Text,
                 SalerId = cmbSaler.SelectedValue != null ? (int?)cmbSaler.SelectedValue : (int?)null,
                 FavoriteProduct = txtFavoriteProduct.Text
             };
             CustomerService customerService = new CustomerService();
             bool result = customerService.AddCustomer(customer);
             if (result)
             {
                 MessageBox.Show("Khách hàng được tạo thành công");
                 if (this.CallFromUserControll != null && this.CallFromUserControll is CustomerList)
                 {
                     ((CustomerList)this.CallFromUserControll).loadCustomerList();
                 }
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
         preventClosing = true;
 }