// Occurs whenever user edit data get uploaded successfully
            private void OnReportDataUploadSucceed(object sender, EditUserEventArgs e)
            {
                // Displays appropriate logs informing user that application successfully committed the data.
                this._consolesServices.OnEditUser_ReportDataUploadSucceed(sender, e);
                this._consolesServices.OnBackToIdle(sender, e);

                // Enables/Disables appropriate controls.
                this._controlsEnabler.OnEditUser_ReportDataUploadSucceed(sender, e);
            }
            // Occurs whenever edit user data failed to get uploaded.
            private void OnReportDataUploadFailed(object sender, EditUserEventArgs e)
            {
                // Displays appropriate logs informing user about failed data upload.
                this._consolesServices.OnEditUser_ReportDataUploadFailed(sender, e);

                // Informs user about application failed to edit user and as such being unable to continue.
                MessageBox.Show("Application failed to edit user and must be closed.", "Edit User failed.", MessageBoxButtons.OK);

                // Close the application.
                this._form.Close();
            }
            private void OnAttemptToEditLoggedInUser(object sender, EditUserEventArgs e)
            {
                // Displays appropriate logs informing user about failed data upload.
                this._consolesServices.OnEditUser_AttemptToEditLoggedInUser(sender, e);

                // Informs user about application edit user because saturn 5 was
                MessageBox.Show("Unable to edit currently logged in user.", "Unable to edit User.", MessageBoxButtons.OK);

                // Cancel saturn 5 removal operation.
                this.OnReportDataUploadCanceled(sender, e);
            }
            // Occurs whenever edit user data canceled to get uploaded.
            private void OnReportDataUploadCanceled(object sender, EditUserEventArgs e)
            {
                // Displays appropriate logs informing user that application canceled data upload
                this._consolesServices.OnEditUser_ReportDataUploadCanceled(sender, e);
                this._consolesServices.OnBackToIdle(sender, e);

                // Clears the content of all of the main form text boxes displaying User/Satur5 etc. data.
                this._dataDisplayServices.ClearAllDataDisplayTextBoxes(sender, e);

                // Clears info boxes
                this._dataDisplayServices.ClearInfoBoxes(sender, e);

                // Enables/Disables appropriate controls.
                this._controlsEnabler.OnEditUser_ReportDataUploadCanceled(sender, e);
            }
 protected void ButtonSave_Click(object sender, EventArgs e)
 {
     if (userId != 0)
     {
         var editUser = new EditUserEventArgs(userId);
         editUser.FirstName   = this.TextBoxFirstName.Text;
         editUser.LastName    = this.TextBoxLastName.Text;
         editUser.UserName    = this.TextBoxUserName.Text;
         editUser.PhoneNumber = this.TextBoxPhone.Text;
         editUser.Email       = this.TextBoxEmail.Text;
         editUser.City        = this.TextBoxCity.Text;
         editUser.Address     = this.TextBoxAddress.Text;
         this.UserEdit?.Invoke(sender, editUser);
         Response.Redirect("~/users/all");
     }
 }
            // Occurs whenever edit user report has been provided and required to be committed.
            private void OnReportDataUploadRequired(object sender, EditUserEventArgs e)
            {
                // Displays appropriate logs/application state/user instructions text to the user.
                this._consolesServices.OnEditUser_UploadingReportDataBegan(sender, e);

                // Attempt to commit edit user data
                Task editUserTask = this._userServices.EditAsync(e.ToBeEdited.Username, e.NewFirstName, e.NewSurname, e.NewUserType);

                editUserTask.ContinueWith((t) =>
                {
                    switch (t.Status)
                    {
                    case TaskStatus.RanToCompletion:
                        // ... execute if user edit committed successfully
                        this.OnReportDataUploadSucceed(sender, e);
                        break;

                    case TaskStatus.Faulted:
                        // ... get flatten collection of exception responsible for the task failure.
                        IReadOnlyCollection <Exception> innerExceptions = t.Exception.Flatten().InnerExceptions;

                        // If task failed because edited user is currently logged in..
                        if (innerExceptions.Any(ex => ex.GetType() == typeof(AttemptToEditLoggedInUserException)))
                        {
                            // .. OnAttemptToEditLogged
                            this.OnAttemptToEditLoggedInUser(sender, e);
                        }
                        // Otherwise if task failed because of some other reason...
                        else
                        {
                            this.OnReportDataUploadFailed(sender, e);
                        }
                        break;

                    case TaskStatus.Canceled:
                        // ... execute if user edit has been canceled to commit
                        this.OnReportDataUploadCanceled(sender, e);
                        break;
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        public void EditUsersPresenter_EditUser_ShouldEditLastName()
        {
            var view = new Mock <IEditUserView>();

            view.SetupAllProperties();
            var usersData = new Mock <IUsersData>();
            var user      = new AspNetUser()
            {
                Id = 1
            };

            usersData.Setup(u => u.UsersRepository.GetUserById(It.IsAny <int>())).Returns(user);

            var presenter = new EditUserPresenter(view.Object, usersData.Object);

            view.Raise(v => v.GetUser += null, view.Object, new GetUserByIdEventArgs(1));
            var editedUserEventArgs = new EditUserEventArgs(1);

            editedUserEventArgs.LastName = "Ivanov";
            view.Raise(v => v.UserEdit  += null, view.Object, editedUserEventArgs);

            usersData.Verify(x => x.UsersRepository.UpdateUser(It.Is <AspNetUser>(u => u.LastName == "Ivanov")));
        }
示例#8
0
        private void EditUser(object sender, EditUserEventArgs e)
        {
            if (this.currentUser == null || this.currentUser.Id != e.Id)
            {
                throw new HttpException(404, "File Not Found!");
            }

            if (e.FirstName != null && e.FirstName != string.Empty)
            {
                this.currentUser.FirstName = e.FirstName;
            }

            if (e.LastName != null && e.FirstName != string.Empty)
            {
                this.currentUser.LastName = e.LastName;
            }

            if (e.PhoneNumber != null && e.PhoneNumber != string.Empty)
            {
                this.currentUser.PhoneNumber = e.PhoneNumber;
            }

            if (e.PostalCode != null && e.PostalCode != string.Empty)
            {
                this.currentUser.PostalCode = e.PostalCode;
            }

            if (e.State != null && e.State != string.Empty)
            {
                this.currentUser.State = e.State;
            }

            if (e.UserName != null && e.UserName != string.Empty)
            {
                this.currentUser.UserName = e.UserName;
            }

            if (e.Email != null && e.Email != string.Empty)
            {
                this.currentUser.Email = e.Email;
            }

            if (e.City != null && e.City != string.Empty)
            {
                this.currentUser.City = e.City;
            }

            if (e.Address != null && e.Address != string.Empty)
            {
                this.currentUser.Address = e.Address;
            }

            try
            {
                this.usersData.UsersRepository.UpdateUser(this.currentUser);
                this.usersData.Save();
            }
            catch (Exception)
            {
                throw new HttpException(500, "Internal Server Error");
            }
        }