示例#1
0
 public void Setup()
 {
     _webContentService = new Mock<IWebContentService>().Object;
     _feedFinder = new Mock<IFeedFinder>().Object;
     _user = new Mock<User> { CallBase = true }.Object;
     _userTasks = new UserTasks(null, null, null, _webContentService, _feedFinder, null, null, null, null, null, null, null);
 }
示例#2
0
 public virtual void AddComment(string commentText, User user)
 {
     _comments.Add(
         new Comment
         {
             CommentText = commentText,
             CreateDate = DateTime.UtcNow,
             Post = this,
             User = user
         });
 }
示例#3
0
        public virtual bool HasNewMessagesFor(User user)
        {
            //quick fail
            if (!HasUnreadMessages)
            {
                return false;
            }

            //get the last user that send a message
            var lastSender = _messages.First().Sender;

            return lastSender.Id != user.Id;
        }
        public IList<InterestInCommonDto> GetInterestsInCommon(User viewingUser, User user)
        {
            var interestsInCommon = _userInterestRepository.GetInterestsInCommon(viewingUser, user).ToList();
            _interestScoreCalculator.CalculateRelatedInterestScore(interestsInCommon);
            var scoredInterests = interestsInCommon.Select(x => new ScoredInterestInCommonDto(x.Id, x.Score, x.Name, x.IsMainCategory, x.IsExactMatch)).ToList();
            scoredInterests = _highestScoreCalculator.CalculateHighestScores(scoredInterests).Cast<ScoredInterestInCommonDto>().ToList();
            _mainCategoryScoreCalculator.CalculateMainCategoryScores(scoredInterests);
            scoredInterests = _closeInterestLimiter.LimitCloseInterests(scoredInterests).Cast<ScoredInterestInCommonDto>().ToList();

            return scoredInterests
                .Select(x => new InterestInCommonDto(x.Name, x.Score, x.IsExactMatch))
                .ToList();
        }
        public PostOverviewApiModel GetPostOverview(int postId, User viewingUser)
        {
            var retVal = new PostOverviewApiModel();
            var post = _postTasks.Get(postId);
            retVal.PostId = post.Id;
            retVal.Username = post.User.Username;
            retVal.Headline = post.User.Headline;
            retVal.AuthorImageUrl = post.User.ProfileImage != null ? post.User.ProfileImage.ImageData.MediumFileName : Constants.DEFAULT_PROFILE_IMAGE;
            retVal.ImageDescription = post.Description;
            retVal.IsLikedByUser = post.Likes.Any(x => x.User == viewingUser);

            if (post.Medium is Video)
            {
                retVal.VideoUrl = ((Video)post.Medium).VideoUrl;
            }
            else if(post.Medium is WebPage){
                retVal.WebPageUrl = ((WebPage)post.Medium).LinkUrl;
            }
            else{
                //this is an image
                retVal.ImageUrl = ((Image)post.Medium).ImageData.FullFileName;
            }

            retVal.Activity = post.Comments.Select(
                x => new PostOverviewApiModel.ActivityViewModel
                {
                    CommentText = x.CommentText,
                    Username = x.User.Username,
                    ProfileImageUrl = x.User.ProfileImage.ImageData.MediumFileName
                }).ToList();

            var commonInterests = _userInterestTasks.GetInterestsInCommon(viewingUser, post.User);
            retVal.CommonInterests = commonInterests.Select(x => new PostOverviewApiModel.CommonInterestViewModel { Name = x.Name }).ToList();
            retVal.HasCommonIntersts = commonInterests.Any();
            return retVal;
        }
示例#6
0
        public User Create(UserCreateDto userToCreate, LocationData location)
        {
            string salt = PasswordHelper.GenerateSalt(16); //TODO: should this be 32 - encapsulate this somehwere
            string pHash = PasswordHelper.GetPasswordHash(userToCreate.Password, salt);

            var user = new User(userToCreate.Username, userToCreate.Email, pHash, salt)
            {
                CreateDate = DateTime.UtcNow
            };

            MajorLocation majorLocation = _locationService.GetNearestMajorCity(location.Latitude, location.Longitude);

            user.UpdateBio("I ♥ " + string.Join(", ", user.Interests.Select(x => x.Interest.Name)));
            user.UpdateHeadline("I am " + user.Username + ", hear me roar!");
            user.UpdateLocation(location, majorLocation);

            user.UpdateCreateDate();

            _userRepository.SaveOrUpdate(user);

            ProcessUserInterests(user, userToCreate.InterestDtos);

            return user;
        }
示例#7
0
        public void AddInterestToUser(User user, int interestId)
        {
            if (interestId < 1)
            {
                throw new RulesException("InterestId", "An existing interest must be passed in");
            }

            ProcessUserInterests(user, new[] { new UserAddInterestDto(interestId) });
        }
示例#8
0
        private void ProcessUserInterests(User user, IEnumerable<UserAddInterestDto> interestDtos)
        {
            foreach (UserAddInterestDto interestDto in interestDtos)
            {
                Interest interest = interestDto.Id > 0
                                        ? _interestTasks.Get(interestDto.Id)
                                        : _interestTasks.Create(interestDto.Name, interestDto.RelatedTo);

                var userInterest = user.AddInterest(interest, null);
                _userInterestTasks.SaveUserInterest(userInterest);
            }
        }
示例#9
0
        public void PostImage(User user, int userInterestId, string description, string imageUrl)
        {
            imageUrl = imageUrl.FormatWebAddress();

            //TODO: DRY this up..the formatWebAddress, the byte[], the streams (videos, iframe, etc)
            byte[] data = _webContentService.GetDataFromUrl(imageUrl);

            string fileName = Path.GetFileName(imageUrl);

            using (var memoryStream = new MemoryStream(data))
            {
                PostImage(user, new FileStreamDto(memoryStream, fileName), userInterestId, description);
            }
        }
示例#10
0
 /// <summary>
 /// a conversation between two people
 /// </summary>
 /// <param name="user1"></param>
 /// <param name="user2"></param>
 public Conversation(User sender, User recipient)
 {
     AddUser(sender);
     AddUser(recipient);
 }
示例#11
0
 public void Login(User user, bool stayLoggedIn)
 {
     user.UpdateLastActivity();
     _userAuthentication.Login(user.Username, stayLoggedIn, user.Role);
 }
示例#12
0
        public Message ReplyToConversation(Conversation conversation, User sender, User receiver, string messageText, string subject, string body)
        {
            Message retVal = null;

            if (sender != null)
            {
                //TODO - don't just check or null - throw ex or don't check at all
                if (conversation != null)
                {
                    retVal = sender.WriteMessage(messageText);

                    conversation.AddMessage(retVal);

                    _emailService.SendMail(receiver.Email, subject, body);
                }
            }
            return retVal;
        }
示例#13
0
 public void RemovePost(User user, int postId)
 {
     var post = user.GetPost(postId);
     ImageFileNamesDto originalImageNames = GetImageFileNamesDto(post.Medium);
     DeleteImages(originalImageNames);
     user.RemoveInterestPost(post);
 }
示例#14
0
        public void RemoveInterest(User user, int interestId)
        {
            UserInterest interest = user.GetInterest(interestId);

            user.RemoveInterest(interest);

            _userInterestTasks.DeleteUserInterest(interest);
        }
示例#15
0
        public void PostWebPage(User user, int userInterestId, string linkUrl)
        {
            UserInterest interest = user.Interests.First(x => x.Id == userInterestId);

            linkUrl = linkUrl.FormatWebAddress();
            string html = _webContentService.GetHtmlFromUrl(linkUrl);
            PageDetails details = _pageParsingService.GetDetails(html);

            string description = details.Description;

            var uri = new Uri(linkUrl);
            var domain = uri.GetLeftPart(UriPartial.Authority).Replace(uri.GetLeftPart(UriPartial.Scheme), "");

            var medium = new WebPage { LinkUrl = linkUrl, WebPageDomainName = domain, Title = details.Title, CreateDate = DateTime.UtcNow };
            var post = new Post { Description = description, CreateDate = DateTime.UtcNow, Medium = medium };

            //determine if image is available
            if (!string.IsNullOrWhiteSpace(details.ImageUrl))
            {
                byte[] data = _webContentService.GetDataFromUrl(details.ImageUrl);
                string fileName = Path.GetFileName(details.ImageUrl);
                using (var memoryStream = new MemoryStream(data))
                {
                    var fileStreamDto = new FileStreamDto(memoryStream, fileName);
                    SaveImageForUser(
                        fileStreamDto, user.Username + "-Interest-WebPage-Image-" + interest.Interest.Name, imgFileNamesDto =>
                                                                                                            medium.AddImage(
                                                                                                                new ImageData(fileName, imgFileNamesDto.ThumbFilename, imgFileNamesDto.MediumFilename, imgFileNamesDto.FullFilename)));
                }
            }

            user.AddPost(post, interest.Interest);
        }
示例#16
0
        public void PostVideo(User user, int userInterestId, string videoUrl)
        {
            UserInterest interest = user.Interests.First(x => x.Id == userInterestId);

            videoUrl = videoUrl.FormatWebAddress();
            string html = _webContentService.GetHtmlFromUrl(videoUrl);
            PageDetails details = _pageParsingService.GetDetails(html);

            string description = details.Description;

            if (string.IsNullOrWhiteSpace(details.VideoUrl))
            {
                throw new RulesException("Description", "Invalid video");
            }

            var medium = new Video { VideoUrl = details.VideoUrl, Title = details.Title, CreateDate = DateTime.UtcNow };

            var post = new Post { Medium = medium, Description = description, CreateDate = DateTime.UtcNow };

            //determine if image is available
            if (!string.IsNullOrWhiteSpace(details.ImageUrl))
            {
                byte[] data = _webContentService.GetDataFromUrl(details.ImageUrl);
                string fileName = Path.GetFileName(details.ImageUrl);
                using (var memoryStream = new MemoryStream(data))
                {
                    var fileStreamDto = new FileStreamDto(memoryStream, fileName);
                    SaveImageForUser(
                        fileStreamDto, user.Username + "-Interest-Video-Image-" + interest.Interest.Name, imgFileNamesDto =>
                                                                                                          medium.AddImage(
                                                                                                              new ImageData(fileName, imgFileNamesDto.ThumbFilename, imgFileNamesDto.MediumFilename, imgFileNamesDto.FullFilename)));
                }
            }

            user.AddPost(post, interest.Interest);
        }
示例#17
0
 public void PostStatus(User user, int userInterestId, string description)
 {
     UserInterest interest = user.Interests.First(x => x.Id == userInterestId);
     var post = new Post { Description = description, CreateDate = DateTime.UtcNow };
     user.AddPost(post, interest.Interest);
 }
示例#18
0
 public void SaveComment(SavePostCommentDto postCommentDto, User user)
 {
     var post = _postRepository.Get(postCommentDto.PostId);
     post.AddComment(postCommentDto.CommentText, user);
 }
示例#19
0
 public void SaveLike(int postId, User user)
 {
     var post = _postRepository.Get(postId);
     post.AddLike(user);
 }
示例#20
0
        public void SaveLocation(User user, LocationData locationData)
        {
            MajorLocation majorLocation = _locationService.GetNearestMajorCity(locationData.Latitude, locationData.Longitude);

            user.UpdateLocation(locationData, majorLocation);
        }
示例#21
0
 public Message(User user,  String text)
 {
     SendDate = DateTime.UtcNow;
     Text = text;
     Sender = user;
 }
示例#22
0
        public void SavePassword(User user, string password)
        {
            string salt = PasswordHelper.GenerateSalt(16); //TODO: should this be 32 - encapsulate this somehwere
            string pHash = PasswordHelper.GetPasswordHash(password, salt);

            user.UpdatePassword(pHash, salt);
        }
示例#23
0
 private void AddUser(User user)
 {
     user.Subscribe(this);
     _users.Add(user);
 }
示例#24
0
 public virtual void AddLike(User user)
 {
     _likes.Add(new Like { CreateDate = DateTime.UtcNow, Post = this, User = user });
 }
示例#25
0
        public void SaveProfileImage(User user, FileStreamDto profileImage)
        {
            ImageFileNamesDto originalImageNames = null;
            if (user.ProfileImage != null)
            {
                originalImageNames = GetImageFileNamesDto(user.ProfileImage);
            }

            SaveImageForUser(
                profileImage, user.Username + "-Profile-Image", imgFileNamesDto =>
                {
                    user.UpdateProfileImage(new ImageData(profileImage.FileName, imgFileNamesDto.ThumbFilename, imgFileNamesDto.MediumFilename, imgFileNamesDto.FullFilename));
                    if (originalImageNames != null)
                    {
                        DeleteImages(originalImageNames);
                    }
                });
        }
示例#26
0
 public void PostImage(User user, FileStreamDto interestImage, int userInterestId, string description)
 {
     UserInterest interest = user.Interests.First(x => x.Id == userInterestId);
     SaveImageForUser(
         interestImage,
         user.Username + "-Interest-Image-" + interest.Interest.Name,
         imgFileNamesDto =>
         user.AddPost(
             new Post
             {
                 Description = description,
                 CreateDate = DateTime.UtcNow,
                 Medium =
                     new Image
                     {
                         ImageData =
                             new ImageData(
                             interestImage.FileName
                             , imgFileNamesDto.ThumbFilename
                             , imgFileNamesDto.MediumFilename
                             , imgFileNamesDto.FullFilename),
                         CreateDate = DateTime.UtcNow
                     }
             }, interest.Interest));
 }
示例#27
0
 private void FillBaseProperties(UserProfileViewModel retVal, User user, IPrincipal requestingUser)
 {
     retVal.Id = user.Id;
     retVal.Headline = user.Headline;
     retVal.Username = user.Username;
     if (user.Username == requestingUser.Identity.Name)
     {
         retVal.AuthenticatedProfileOwner = true;
     }
     else if (requestingUser.Identity.IsAuthenticated)
     {
         retVal.AuthenticatedVisitor = true;
     }
     if (user.ProfileImage != null)
     {
         retVal.ProfileImageUrl = user.ProfileImage.ImageData.MediumFileName;
         retVal.FullProfileImageUrl = user.ProfileImage.ImageData.FullFileName;
     }
 }
示例#28
0
        public void SaveWebsite(User user, string siteUrl)
        {
            if (string.IsNullOrWhiteSpace(siteUrl)) throw new ArgumentNullException("siteUrl");

            siteUrl = siteUrl.FormatWebAddress();

            if (!UrlValidation.IsValidUrl(siteUrl)) throw new RulesException("SiteUrl", "Invalid URL");

            string html = _webContentService.GetHtmlFromUrl(siteUrl);

            string feedUrl = _feedFinder.GetFeedUrl(html);

            if (string.IsNullOrWhiteSpace(feedUrl))
            {
                feedUrl = null;
            }

            user.UpdateWebsite(siteUrl, feedUrl);
        }