Beispiel #1
0
        public RemoveModershipResponse RemoveModership(ISession session, RemoveModershipRequest request)
        {
            var response = request.CreateResponse<RemoveModershipResponse>();
            if (session.User.Role != UserRole.Admin)
            {
                //access denied
                return response;
            }

            User targetUser = null;
            using (var uow = UnitOfWorkFactory.Create())
            {
                targetUser = uow.UsersRepository.FirstMatching(UserSpecification.Id(request.TargetUserId));
                if (targetUser == null)
                {
                    //User not found
                    return response;
                }

                targetUser.RemoveModeratorship();
                uow.Commit();
            }

            response.Success = true;
            _sessionManager.SendToEachChatSessions(new ModershipRemovedInfo
                {
                    ActorName = session.User.Name,
                    TargetName = targetUser.Name,
                    TargetId = targetUser.Id,
                });

            //success
            return response;
        }