コード例 #1
0
ファイル: UserService.cs プロジェクト: jzaja/BetterConnect
        public User AddInterest(int userId, string interestName)
        {
            User     user     = (User)_userRepo.Get(userId);
            Interest interest = _interestRepository.GetByName(interestName);

            if (user.Interests.Contains(interest))
            {
                return(null);
            }

            if (interest == null)
            {
                Interest newInterest = new Interest {
                    Name = interestName
                };

                var saved = _interestRepository.Save(newInterest);
                saved.AddUser(user);

                _interestRepository.Update(saved);
            }
            else
            {
                interest.AddUser(user);
                _interestRepository.Update(interest);
            }

            return(user);
        }
コード例 #2
0
        public void TestGetByName()
        {
            var interest = new Interest {
                Name = "Skijanje"
            };

            _interestRepo.Save(interest);

            Assert.NotNull(_interestRepo.GetByName("skijanje"));
            Assert.NotNull(_interestRepo.GetByName("Skijanje"));
            Assert.NotNull(_interestRepo.GetByName("SkIjAnjE"));
            Assert.Null(_interestRepo.GetByName("nepostojece"));
        }