상속: Entity
        /// <summary>
        /// </summary>
        public RegistrationResponse RegisterNewUser(ISession session, RegistrationRequest request)
        {
            var response = request.CreateResponse(new RegistrationResponse { Result = RegistrationResponseType.Success });
            User user = null;
            
            try
            {
                user = new User(request.Name, request.Password, request.Huid, request.Sex, request.Age, request.PushUri, request.Country, request.Platform);
            }
            catch (InvalidUserRegistrationDataException)
            {
                response.Result = RegistrationResponseType.InvalidData;
                return response;
            }

            using (var uow = UnitOfWorkFactory.Create())
            {
                if (uow.UsersRepository.AnyMatching(UserSpecification.Name(user.Name)))
                {
                    response.Result = RegistrationResponseType.NameIsInUse;
                    return response;
                }

                uow.UsersRepository.Add(user);
                uow.Commit();
            }
            response.User = user.ProjectedAs<UserDto>();
            session.SetUser(user);
            return response;
        }
 public PublicMessage(User author, int imageId, string body)
 {
     Author = author;
     AuthorName = author.Name;
     Timestamp = DateTime.UtcNow;
     Body = body;
     ImageId = imageId;
 }
 public PublicMessage(User author, string body)
 {
     Author = author;
     AuthorName = author.Name;
     Timestamp = DateTime.UtcNow;
     Body = body.CutIfLonger();
     if (string.IsNullOrEmpty(Body))
         throw new ArgumentNullException();
     Timestamp = DateTime.UtcNow;
 }
 public static Specification<PublicMessage> Author(User user)
 {
     return new DirectSpecification<PublicMessage>(m => m.Author == user);
 }
예제 #5
0
        public void BringVoiceBack(User actor)
        {
            if (actor.Role != UserRole.Moderator && actor.Role != UserRole.Admin)
                throw new ModeratorsRightsRequiredException();

            if (Role == UserRole.Admin || Role == UserRole.Moderator)
                throw new ModeratorsRightsRequiredException();

            IsDevoiced = false;
        }
예제 #6
0
        public void Devoice(User devoicedBy)
        {
            if (devoicedBy.Role != UserRole.Moderator && devoicedBy.Role != UserRole.Admin)
                throw new ModeratorsRightsRequiredException();

            if (Role == UserRole.Admin || Role == UserRole.Moderator)
                throw new ModeratorsRightsRequiredException();

            IsDevoiced = true;
            DevoicedAt = DateTime.UtcNow;
        }
예제 #7
0
        /// <summary>
        /// Reset user's photo to default (in case if it's some kind of pornography ;)
        /// </summary>
        /// <param name="resetAuthor"></param>
        public int ResetPhoto(User resetAuthor)
        {
            if (resetAuthor.Role != UserRole.Moderator && resetAuthor.Role != UserRole.Admin)
                throw new ModeratorsRightsRequiredException();

            return PhotoId = -1;
        }
예제 #8
0
        public void UnBan(User actor)
        {
            if (actor.Role != UserRole.Moderator && actor.Role != UserRole.Admin)
                throw new ModeratorsRightsRequiredException();

            if (Role == UserRole.Admin || Role == UserRole.Moderator)
                throw new ModeratorsRightsRequiredException();

            IsBanned = false;
        }
예제 #9
0
        public void Ban(User bannedBy)
        {
            if (bannedBy.Role != UserRole.Moderator && bannedBy.Role != UserRole.Admin)
                throw new ModeratorsRightsRequiredException();

            if (Role == UserRole.Admin || Role == UserRole.Moderator)
                throw new ModeratorsRightsRequiredException();

            IsBanned = true;
            BannedAt = DateTime.UtcNow;
        }