// Created By: Trent Cullinan 02/24/2016
        private void btnActionOne_Click(object sender, RoutedEventArgs e)
        {
            if (tiOrgUsers.IsSelected)
            {
                GroupMember user = (GroupMember)dgrdUsers.SelectedItem;

                try
                {
                    lblResponseMessage.Content = orgUserManager.EditUserLeader(this.accessToken, user) ?
                                                 "User changed!" : "Sorry, selected user could not be changed.";

                    BindOrganizationUsers();

                    btnActionOne.Content = user.Leader ?
                                           "Demote" : "Promote";
                }
                catch (Exception ex)
                {
                    lblResponseMessage.Content = "Error: " + ex.Message;
                }
            }
            else if (tiRequests.IsSelected)
            {
                GroupLeaderRequest request = (GroupLeaderRequest)dgrdRequests.SelectedItem;

                if (null != request)
                {
                    try
                    {
                        lblResponseMessage.Content = orgRequestManager.EditApproveRequest(
                            this.accessToken, request, orgUserManager.GetGroupMember(accessToken, request.User)) ?
                                                     "Request Approved" : "Unable to approve";

                        BindLeaderRequests();
                    }
                    catch (Exception ex)
                    {
                        lblResponseMessage.Content = "Error: " + ex.Message;
                    }
                }
                else
                {
                    lblResponseMessage.Content = "Error: Please select a request.";
                }
            }
        }
        // Created By: Trent Cullinan 02/24/2016
        private void btnActionTwo_Click(object sender, RoutedEventArgs e)
        {
            if (tiOrgUsers.IsSelected)
            {
                GroupMember user = (GroupMember)dgrdUsers.SelectedItem;

                try
                {
                    OrgManageUserGroups orgManageUserGroups = new OrgManageUserGroups(
                        this.accessToken, this.orgUserManager, user);

                    NavigationService.Navigate(orgManageUserGroups);
                }
                catch (Exception ex)
                {
                    lblResponseMessage.Content = "Error: " + ex.Message;
                }
            }
            else if (tiRequests.IsSelected)
            {
                GroupLeaderRequest request = (GroupLeaderRequest)dgrdRequests.SelectedItem;

                if (null != request)
                {
                    try
                    {
                        lblResponseMessage.Content = orgRequestManager.EditDeclineRequest(accessToken, request) ?
                                                     "Request Declined" : "Unable to decline";

                        BindLeaderRequests();
                    }
                    catch (Exception ex)
                    {
                        lblResponseMessage.Content = "Error: " + ex.Message;
                    }
                }
                else
                {
                    lblResponseMessage.Content = "Error: Please select a request.";
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Decline a current request.
        /// Created By: Trent Cullinan 02/24/2016
        /// </summary>
        /// <param name="accessToken">Confirm user is valid to use method.</param>
        /// <param name="request">Request to be declined.</param>
        /// <returns>Whether process was successful.</returns>
        public bool EditDeclineRequest(AccessToken accessToken, GroupLeaderRequest request)
        {
            bool flag = false;

            if (GetAccessToken(accessToken, this.organization))
            {
                // Do nothing with request.
                flag = 1 == orgUserAccessor.ProcessRequest(accessToken, request); // 1 row should be affected.

                if (flag)
                {
                    // Remove request.
                    this.orgRequests = this.orgRequests.Except(this.orgRequests.Where(r => r.RequestID == request.RequestID));
                }
            }
            else
            {
                throw new Exception("User is not the leader of the organization.");
            }

            return(flag);
        }
        /// <summary>
        /// Confirm that a request has been processed.
        /// Created By: Trent Cullinan 02/24/2016
        /// </summary>
        /// <param name="accessToken">Confirm user is valid to use method.</param>
        /// <param name="request">Request to be confirmed processed.</param>
        /// <returns>Number of records processed.</returns>
        public int ProcessRequest(AccessToken accessToken, GroupLeaderRequest request)
        {
            int rowsAffected = 0;

            if (CheckAccessToken(accessToken, this.organization))
            {
                var conn = DBConnection.GetDBConnection();

                var cmd = new SqlCommand("Gardens.spUpdateOrgGroupLeaderRequest", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@RequestID",
                                            request.RequestID);
                cmd.Parameters.AddWithValue("@UserID",
                                            accessToken.UserID);

                try
                {
                    conn.Open();

                    rowsAffected = cmd.ExecuteNonQuery();
                }
                catch (SqlException)
                {
                    throw;
                }
                finally
                {
                    conn.Close();
                }
            }
            else
            {
                throw new ArgumentException();
            }

            return(rowsAffected);
        }
Beispiel #5
0
        /// <summary>
        /// Approve a current request.
        /// Created By: Trent Cullinan 02/24/2016
        /// </summary>
        /// <param name="accessToken">Confirm user is valid to use method.</param>
        /// <param name="request">Request to be approved.</param>
        /// <param name="groupMember">User to be changed.</param>
        /// <returns>Whether process was successful.</returns>
        public bool EditApproveRequest(AccessToken accessToken, GroupLeaderRequest request, GroupMember groupMember)
        {
            bool flag = false;

            if (GetAccessToken(accessToken, this.organization))
            {
                int result = orgUserAccessor.AddLeaderToGroup(accessToken, request.Group, groupMember) +
                             orgUserAccessor.ProcessRequest(accessToken, request);

                flag = 2 == result; // 2 rows should be affected.

                if (flag)
                {
                    // Remove request.
                    this.orgRequests = this.orgRequests.Except(this.orgRequests.Where(r => r.RequestID == request.RequestID));
                }
            }
            else
            {
                throw new Exception("User is not the leader of the organization.");
            }

            return(flag);
        }