Beispiel #1
0
        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);
        }
Beispiel #2
0
        public async Task <Result> UpdateInterest(InterestDTO interestDTO)
        {
            if (interestDTO == null)
            {
                return(Result.Fail(Constants.InterestErrorMessages.Interest_Should_Not_Be_Empty));
            }
            var interest = Interest.Create(interestDTO.InterestName, interestDTO.InterestDescription);

            if (!interest.IsSuccessed)
            {
                return(Result.Fail(interest.GetErrorString()));
            }
            var actualInterest = await _interestRepository.GetInterestById(interestDTO.Id);

            if (!actualInterest.IsSuccessed)
            {
                return(Result.Fail(actualInterest.GetErrorString()));
            }
            actualInterest.Value.UpdateInterest(interest.Value);
            _interestRepository.Update(actualInterest.Value);
            return(await _interestRepository.SaveChangesAsync(InterestErrorMessages.Error_Occured_While_Updating_Interest));
        }