Exemplo n.º 1
0
        public async Task <JsonResult> DeleteMember(string accountName, string memberName)
        {
            var account = GetAccount(accountName);

            var currentUser = GetCurrentUser();

            if (account == null ||
                (currentUser.Username != memberName &&
                 ActionsRequiringPermissions.ManageMembership.CheckPermissions(currentUser, account)
                 != PermissionsCheckResult.Allowed))
            {
                return(Json(HttpStatusCode.Forbidden, Strings.Unauthorized));
            }

            if (!account.Confirmed)
            {
                return(Json(HttpStatusCode.BadRequest, Strings.Member_OrganizationUnconfirmed));
            }

            try
            {
                var removedMember = await UserService.DeleteMemberAsync(account, memberName);

                await MessageService.SendOrganizationMemberRemovedNoticeAsync(account, removedMember);

                return(Json(Strings.DeleteMember_Success));
            }
            catch (EntityException e)
            {
                return(Json(HttpStatusCode.BadRequest, e.Message));
            }
        }