示例#1
0
        private void editcreateuserbtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(usernametxtbox.Text) || string.IsNullOrEmpty(surnametxtbox.Text) || string.IsNullOrEmpty(fintxtbox.Text) || string.IsNullOrEmpty(numbertxtbox.Text) || string.IsNullOrEmpty(emailtxtbox.Text))
            {
                MessageBox.Show("Fill all fields", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (fintxtbox.Text.Length < 7)
            {
                MessageBox.Show("Invalid FIN", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            Customer customer = new Customer()
            {
                Name        = usernametxtbox.Text,
                Surname     = surnametxtbox.Text,
                FIN         = fintxtbox.Text,
                PhoneNumber = numbertxtbox.Text,
                Email       = emailtxtbox.Text,
            };

            if (isEdit)
            {
                AddUpdateResponseModel result = customerRepository.UpdateCustomer(customer);
                if (result.Status)
                {
                    MessageBox.Show("User Edited", "Edited", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(result.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                AddUpdateResponseModel result = customerRepository.AddCustomer(customer);

                if (result.Status)
                {
                    MessageBox.Show("User Created", "Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(result.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            customerdatagrid.DataSource = customerRepository.GetAllCustomers();
            clearbtn_Click(sender, e);
        }
示例#2
0
        private void editcreateuserbtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(usernametxtbox.Text) || string.IsNullOrEmpty(surnametxtbox.Text) || string.IsNullOrEmpty(fintxtbox.Text) || string.IsNullOrEmpty(numbertxtbox.Text) || string.IsNullOrEmpty(emailtxtbox.Text))
            {
                MessageBox.Show("Fill all fields", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (fintxtbox.Text.Length < 7)
            {
                MessageBox.Show("Invalid FIN", "Warning!!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            AppUsers appUser = new AppUsers()
            {
                Name        = usernametxtbox.Text,
                Surname     = surnametxtbox.Text,
                FIN         = fintxtbox.Text,
                PhoneNumber = numbertxtbox.Text,
                Email       = emailtxtbox.Text,
                Password    = passwordtxtbox.Text,
                rolesId     = (int)rolecombobox.SelectedValue
            };

            if (isEdit)
            {
                AddUpdateResponseModel result = accountRepository.UpdateUser(appUser);
                if (result.Status)
                {
                    MessageBox.Show("User Edited", "Edited", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show(result.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(passwordtxtbox.Text.Trim()))
                {
                    AddUpdateResponseModel result = accountRepository.AddUser(appUser);

                    if (result.Status)
                    {
                        MessageBox.Show("User Created", "Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(result.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Incorrect password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            userdatagrid.DataSource = accountRepository.GetAppUsers();
            clearbtn_Click(sender, e);
        }