示例#1
0
 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;
 }
示例#2
0
        public void AttachShouldIgnoreOldValues()
        {
            var player = new User("Egor", "qwerty", "HUID", true, 24, "http://pushuri", "Belarus");

            using (var dc1 = new UnitOfWork())
            {
                dc1.UsersRepository.Add(player);
                player.Friends.Add(new User("Friend1", "2", "HUID2", true, 25, "http://pushuri2", "Norway"));
                dc1.SaveChanges();
            }

            //these changes should not be saved into db 
            player.ChangeName("ThisNameShouldNotBeSavedToDbOnNextSaveChanges");

            using (var dc2 = new UnitOfWork())
            {
                dc2.Attach(player);
                player.Friends.Add(new User("Friend2", "3", "HUID3", true, 26, "http://pushuri3", "Norway"));
                player.ChangeCountry("USA");
                dc2.SaveChanges();
            }

            using (var dc3 = new UnitOfWork())
            {
                User persistedUser = dc3.UsersRepository.FirstMatching(UserSpecification.Id(player.Id));
                Assert.AreEqual("Egor", persistedUser.Name);
                Assert.AreEqual("USA", persistedUser.Country);
                Assert.AreEqual(2, persistedUser.Friends.Count);

                persistedUser.Friends.Add(new User("Friend3", "4", "HUID4", true, 27, "http://pushuri4", "Norway"));
                dc3.SaveChanges();
            }

            //using (var dc4 = new UnitOfWork())
            //{
            //    dc4.Attach(player);
            //    Assert.AreEqual(3, player.Friends.Count);
            //}
        }
示例#3
0
        /// <summary>
        /// </summary>
        public RegistrationResponse RegisterNewPlayer(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);
                user.ChangePhoto(request.PhotoId);
            }
            catch (InvalidPlayerRegistrationDataException)
            {
                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;
                }
                
                var playerWithSameHuid = uow.UsersRepository.FirstMatching(UserSpecification.Huid(request.Huid));
                if (playerWithSameHuid != null && playerWithSameHuid.IsBanned)
                {
                    response.Result = RegistrationResponseType.Banned;
                    return response;
                }

                uow.UsersRepository.Add(user);
                uow.Commit();
            }
            response.User = user.ProjectedAs<UserDto>();
            return response;
        }
示例#4
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;
        }
示例#5
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;
        }
示例#6
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;
        }
示例#7
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;
        }
示例#8
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;
        }
 public static Specification<PublicMessage> Author(User user)
 {
     return new DirectSpecification<PublicMessage>(m => m.Author == user);
 }