Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var idExists = UserRepo.SearchUserId(this.rtxtId.Text);

            if (idExists)
            {
                if (this.cmbType.Text == "Admin")
                {
                    MessageBox.Show("Can not create a new admin");
                    return;
                }

                try
                {
                    if (!this.UpdateFillEntity())
                    {
                        return;
                    }
                    if (UserRepo.Update(this.User) && LoginRepo.Update(this.Login))
                    {
                        MessageBox.Show("Successfully updated  user");
                        this.rtxtId.Text = UserRepo.GetId();
                        this.ClearUserInput();
                        this.PopulateGridView();
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Cann't update user\n" + error.Message);
                }
            }
            else
            {
                if (this.cmbType.Text == "Admin")
                {
                    MessageBox.Show("Can not create a new admin");
                    return;
                }
                try
                {
                    if (!this.FillEntity())
                    {
                        return;
                    }
                    if (UserRepo.Save(this.User) && LoginRepo.Save(this.Login))
                    {
                        MessageBox.Show("Successfully created new user");
                        this.rtxtId.Text = UserRepo.GetId();
                        this.ClearUserInput();
                        this.PopulateGridView();
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Cann't add user\n" + error.Message);
                }
            }
        }
        public async Task <IActionResult> Save([FromBody] LoginViewModel lvm)
        {
            LoginViewModel login = new LoginViewModel();

            try
            {
                var result = await loginRepo.Update(lvm);

                return(Ok(result));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new EmaintenanceMessage(ex.Message)));
            }
        }