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); }
public virtual void AddComment(string commentText, User user) { _comments.Add( new Comment { CommentText = commentText, CreateDate = DateTime.UtcNow, Post = this, User = user }); }
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; }
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; }
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) }); }
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); } }
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); } }
/// <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); }
public void Login(User user, bool stayLoggedIn) { user.UpdateLastActivity(); _userAuthentication.Login(user.Username, stayLoggedIn, user.Role); }
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; }
public void RemovePost(User user, int postId) { var post = user.GetPost(postId); ImageFileNamesDto originalImageNames = GetImageFileNamesDto(post.Medium); DeleteImages(originalImageNames); user.RemoveInterestPost(post); }
public void RemoveInterest(User user, int interestId) { UserInterest interest = user.GetInterest(interestId); user.RemoveInterest(interest); _userInterestTasks.DeleteUserInterest(interest); }
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); }
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); }
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); }
public void SaveComment(SavePostCommentDto postCommentDto, User user) { var post = _postRepository.Get(postCommentDto.PostId); post.AddComment(postCommentDto.CommentText, user); }
public void SaveLike(int postId, User user) { var post = _postRepository.Get(postId); post.AddLike(user); }
public void SaveLocation(User user, LocationData locationData) { MajorLocation majorLocation = _locationService.GetNearestMajorCity(locationData.Latitude, locationData.Longitude); user.UpdateLocation(locationData, majorLocation); }
public Message(User user, String text) { SendDate = DateTime.UtcNow; Text = text; Sender = user; }
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); }
private void AddUser(User user) { user.Subscribe(this); _users.Add(user); }
public virtual void AddLike(User user) { _likes.Add(new Like { CreateDate = DateTime.UtcNow, Post = this, User = user }); }
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); } }); }
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)); }
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; } }
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); }