public ActionResult CreateTopic(Topic topic, Post post, int id, bool sticky, string excludedUsers, Poll poll) { this.logger.Debug("Creating topic '{0}' with post '{1}' and forumId '{2}'", topic, post, id); post.Author = this.userRepository.GetUserByName(this.User.Identity.Name); topic.Forum = this.forumRepository.GetForumById(id); List <MediaCommUser> usersToExclude = new List <MediaCommUser>(); if (sticky) { topic.DisplayPriority = TopicDisplayPriority.Sticky; } List <string> userNamesToExclude = excludedUsers.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList(); foreach (string userName in userNamesToExclude) { MediaCommUser user = this.userRepository.GetUserByName(userName); usersToExclude.Add(user); } topic.ExcludedUsers = usersToExclude; if (poll != null && !string.IsNullOrEmpty(poll.Question)) { topic.Poll = poll; } Topic createdTopic = this.forumRepository.AddTopic(topic, post); return(this.RedirectToAction("Topic", new { id = createdTopic.Id, name = this.Url.ToFriendlyUrl(createdTopic.Title) })); }
private void SendNewTopicNotificationAsync(Topic newTopic) { this.ExecuteNotification( () => { Topic notifyTopic = this.sessionContainer.CurrentSession.Get <Topic>(newTopic.Id); MediaCommUser author = this.userRepository.GetUserByName(notifyTopic.CreatedBy); DateTime notificationTime = DateTime.Now; IEnumerable <string> usersMailAddressesToNotify = this.userRepository.GetMailAddressesToNotifyAboutNewPost().Where( m => !notifyTopic.ExcludedUsers.Select(u => u.EMailAddress).Contains(m) && m != author.EMailAddress).ToList(); if (!usersMailAddressesToNotify.Any()) { return; } string subject = Mail.NewTopicTitle + General.Title; string body = string.Format(Mail.NewTopicBody, newTopic.CreatedBy, newTopic.Title, newTopic.Created) + "<br /><br />" + General.WebSite; this.SendNotificationMail(subject, body, usersMailAddressesToNotify); this.userRepository.UpdateLastForumsNotification(usersMailAddressesToNotify, notificationTime); }); }
/// <summary>Get the 10 topics with the newest posts.</summary> /// <param name="currentUser">The current user.</param> /// <returns>The 10 topics with the newest posts.</returns> public IEnumerable <Topic> Get10TopicsWithNewestPosts(MediaCommUser currentUser) { List <Topic> topics = this.Session.Query <Topic>().Where(t => !t.ExcludedUsers.Contains(currentUser)).OrderByDescending(t => t.LastPostTime).Take(10).ToList(); this.UpdateTopicReadStatus(topics.Where(t => t.LastPostTime > DateTime.Now - this.topicUnreadValidity), currentUser); return(topics); }
/// <summary>Gets user by name.</summary> /// <param name="userName">Name of the user.</param> /// <returns>The user with the provided name..</returns> public MediaCommUser GetUserByName(string userName) { this.Logger.Debug("Getting user for username '{0}'", userName); MediaCommUser user = this.Session.Query <MediaCommUser>().Single( u => u.UserName.Equals(userName)); this.Logger.Debug("Got user: " + user); return(user); }
/// <summary>Creates an admin user.</summary> /// <param name="userName">Name of the user.</param> /// <param name="password">The password.</param> /// <param name="mailAddress">The mail address.</param> public void CreateAdmin(string userName, string password, string mailAddress) { MediaCommUser user = new MediaCommUser(userName, mailAddress, password) { IsAdmin = true }; this.InvokeTransaction(s => s.Save(user)); }
public void CreateAdmin(string userName, string password, string mailAddress) { MediaCommUser user = new MediaCommUser(userName, mailAddress, password) { IsAdmin = true }; this.Session.Save(user); }
public ActionResult Index() { MediaCommUser currentUser = this.currentUserContainer.User; currentUser.LastVisit = DateTime.Now; this.userRepository.UpdateUser(currentUser); return(this.View(this.forumRepository.GetAllForums())); }
public ActionResult MyProfile() { MediaCommUser currentUser = this.userRepository.GetUserByName(this.User.Identity.Name); IEnumerable <SelectListItem> notificationIntervalList = NotificationInterval.None.ToSelectList(); ViewData["NotificationIntervals"] = notificationIntervalList; return(this.View(currentUser)); }
public ActionResult CompleteUpload(PhotoCategory category, PhotoAlbum album) { album.Name = album.Name.Trim(); album.PhotoCategory = this.photoRepository.GetCategoryById(category.Id); MediaCommUser uploader = this.userRepository.GetUserByName(this.User.Identity.Name); this.photoRepository.AddPhotos(album, uploader); return(this.RedirectToAction("UploadSuccessFull")); }
public void AddPhotos(PhotoAlbum album, MediaCommUser uploader) { string targetPath = this.GetTargetPath(album); string unprocessedPath = Path.Combine(targetPath, UnprocessedPhotosFolder); IEnumerable <FileInfo> newFiles = this.MovePhotos(targetPath, unprocessedPath); this.AddPicturesToDB(newFiles, album, uploader); this.imageGenerator.GenerateImages(targetPath, newFiles); }
/// <summary>Adds the photos in the specified folder to the DB.</summary> /// <param name="album">The album.</param> /// <param name="uploader">The uploader.</param> public void AddPhotos(PhotoAlbum album, MediaCommUser uploader) { this.Logger.Debug("Extracting and adding photos.Album: '{0}, Uploader: '{1}'", album, uploader); string targetPath = this.GetTargetPath(album); string unprocessedPath = Path.Combine(targetPath, UnprocessedPhotosFolder); IEnumerable <FileInfo> newFiles = this.MovePhotos(targetPath, unprocessedPath); this.AddPicturesToDB(newFiles, album, uploader); this.imageGenerator.GenerateImages(targetPath, UnprocessedPhotosFolder); }
/// <summary>Updates the topic read status.</summary> /// <param name="topics">The topics.</param> /// <param name="currentUser">The current user.</param> private void UpdateTopicReadStatus(IEnumerable <Topic> topics, MediaCommUser currentUser) { List <TopicRead> readTopics = this.Session.Query <TopicRead>().Where(r => r.LastVisit > DateTime.Now - this.topicUnreadValidity).ToList(); foreach (Topic topic in topics) { topic.ReadByCurrentUser = readTopics.Any( r => r.ReadByUser.Id == currentUser.Id && r.ReadTopic.Id == topic.Id && topic.LastPostTime < r.LastVisit); } }
public ActionResult MyProfile(string username) { this.logger.Debug("Saving profile changes for user '{0}'", username); MediaCommUser user = this.userRepository.GetUserByName(username); this.UpdateModel(user, "user", null, new[] { "Id", "LastVisit", "UserName", "DateOfBirth" }); this.ViewData["ChangesSaved"] = General.ChangesSaved; this.userRepository.UpdateUser(user); return(this.View(user)); }
public ActionResult MyProfile(string username) { MediaCommUser user = this.userRepository.GetUserByName(username); this.UpdateModel(user, null, null, new[] { "Id", "LastVisit", "UserName" }); this.ViewData["ChangesSaved"] = General.ChangesSaved; IEnumerable <SelectListItem> notificationIntervalList = NotificationInterval.None.ToSelectList(); ViewData["NotificationIntervals"] = notificationIntervalList; this.userRepository.UpdateUser(user); return(this.View(user)); }
public ActionResult Index() { IEnumerable <Topic> topicsWithNewestPosts = this.forumRepository.GetTopicsWithNewestPosts(); IEnumerable <PhotoAlbum> newestPhotoAlbums = this.photoRepository.Get4NewestAlbums(); MediaCommUser currentUser = this.currentUserContainer.User; currentUser.LastVisit = DateTime.Now; this.userRepository.UpdateUser(currentUser); return(this.View(new WhatsNewInfo { Topics = topicsWithNewestPosts, PostsPerTopicPage = PostsPerTopicPage, Albums = newestPhotoAlbums })); }
public ActionResult LogOn(UserLogin userLogin, string returnUrl) { if (this.ModelState.IsValid) { if (this.userRepository.ValidateUser(userLogin.UserName, userLogin.Password)) { string roles = string.Empty; MediaCommUser user = this.userRepository.GetUserByName(userLogin.UserName); if (user.IsAdmin) { roles = "Administrators"; } DateTime expiration = DateTime.Now.AddDays(7); FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( version: 1, name: userLogin.UserName, issueDate: DateTime.Now, expiration: expiration, isPersistent: userLogin.RememberMe, userData: roles, cookiePath: FormsAuthentication.FormsCookiePath); string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); httpCookie.Expires = expiration; this.Response.Cookies.Add(httpCookie); user.LastVisit = DateTime.Now; this.userRepository.UpdateUser(user); return(!string.IsNullOrEmpty(returnUrl) ? (ActionResult)this.Redirect(returnUrl) : this.RedirectToAction("Index", "Home")); } else { this.ModelState.AddModelError(string.Empty, Resources.Users.LoginFailed); } } // If we got this far, something failed, redisplay form return(View(userLogin)); }
/// <summary>Gets the first unread post for the topic.</summary> /// <param name="id">The topic id.</param> /// <param name="user">The current user.</param> /// <returns>The first unread post.</returns> public Post GetFirstUnreadPostForTopic(int id, MediaCommUser user) { /* joins are not supported by linq to nhibernate * Post post = (from p in this.Session.Query<Post>() * join tr in this.Session.Query<TopicRead>() on p.Topic.Id equals tr.ReadTopic.Id * where p.Topic.Id == id && tr.ReadByUser.UserName == user.UserName && p.Created > tr.LastVisit * orderby p.Created descending * select p).FirstOrDefault();*/ DateTime date = (this.Session.Query <TopicRead>().SingleOrDefault( tr => tr.ReadByUser.UserName == user.UserName && tr.ReadTopic.Id == id) ?? new TopicRead { LastVisit = DateTime.Now.AddMonths(-1) }).LastVisit; Post post = this.Session.Query <Post>().Where(p => p.Topic.Id == id && p.Created > date).OrderByDescending(p => p.Created). FirstOrDefault(); return(post); }
private void SendPhotosNotificationAsync(PhotoAlbum albumContainingNewPhoto, string uploaderName) { this.ExecuteNotification( () => { DateTime notificationTime = DateTime.Now; MediaCommUser uploader = this.userRepository.GetUserByName(uploaderName); IEnumerable <string> usersMailAddressesToNotify = this.userRepository.GetMailAddressesToNotifyAboutNewPhotos().Where(m => m != uploader.EMailAddress); if (!usersMailAddressesToNotify.Any()) { return; } string subject = Mail.NewPhotosTitle + General.Title; string body = string.Format(Mail.NewPhotosBody, uploaderName, albumContainingNewPhoto.Name) + "<br /><br />" + General.WebSite; this.SendNotificationMail(subject, body, usersMailAddressesToNotify); this.userRepository.UpdateLastPhotosNotification(usersMailAddressesToNotify, notificationTime); }); }
/// <summary>Gets all forums.</summary> /// <param name="currentUser">The current user.</param> /// <returns>The list of forums.</returns> public IEnumerable <Forum> GetAllForums(MediaCommUser currentUser) { List <Forum> allForums = this.Session.Query <Forum>().ToList(); foreach (Forum forum in allForums) { forum.HasUnreadTopics = bool.Parse(this.Session.CreateSQLQuery( @"select case when COUNT(id) = 0 then 'False' else 'True' end from ForumTopics where ForumID = :forumId and LastPostTime > DATEADD(day, -30, GETDATE()) and Id not in (select ReadTopicID from ForumTopicsRead where ReadByUserID = :userId and LastVisit > DATEADD(day, -30, GETDATE()) and LastVisit > LastPostTime)" ) .SetParameter("forumId", forum.Id) .SetParameter("userId", currentUser.Id) .UniqueResult <string>()); } this.Logger.Debug("Got {0} forums", allForums.Count); return(allForums); }
public ActionResult CreateTopic(Topic topic, Post post, int id, bool sticky, string excludedUsers, Poll poll) { post.Author = this.userRepository.GetUserByName(this.User.Identity.Name); topic.Forum = this.forumRepository.GetForumById(id); List <MediaCommUser> usersToExclude = new List <MediaCommUser>(); if (sticky) { topic.DisplayPriority = TopicDisplayPriority.Sticky; } List <string> userNamesToExclude = excludedUsers.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList(); foreach (string userName in userNamesToExclude) { MediaCommUser user = this.userRepository.GetUserByName(userName); usersToExclude.Add(user); } topic.ExcludedUsers = usersToExclude; if (poll != null && !string.IsNullOrEmpty(poll.Question)) { topic.Poll = poll; topic.Poll.PossibleAnswers = poll.PossibleAnswers.Where(pa => !string.IsNullOrEmpty(pa.Text)).ToList(); } post.Text = HtmlSanitizer.Sanitize(this.markdownConverter.Transform(post.Text)); Topic createdTopic = this.forumRepository.AddTopic(topic, post); this.notificationSender.SendForumsNotification(createdTopic); return(this.RedirectToAction("Topic", new { id = createdTopic.Id, name = this.Url.ToFriendlyUrl(createdTopic.Title) })); }
/// <summary>Shows an user profile.</summary> /// <param name="username">The username.</param> /// <returns>The user profile view.</returns> public ActionResult Profile(string username) { MediaCommUser user = this.userRepository.GetUserByName(username); return(this.View(user)); }
/// <summary>Shows the current user's profile.</summary> /// <returns>The my profile view.</returns> public ActionResult MyProfile() { MediaCommUser currentUser = this.userRepository.GetUserByName(this.User.Identity.Name); return(this.View(currentUser)); }
/// <summary>Updates the user.</summary> /// <param name="user">The user to update.</param> public void UpdateUser(MediaCommUser user) { this.Logger.Debug("Updating user: " + user); this.InvokeTransaction(s => s.Update(user)); }
private void AddPicturesToDB(IEnumerable <FileInfo> filesToAdd, PhotoAlbum album, MediaCommUser uploader) { PhotoAlbum photoAlbum = this.Session.Query <PhotoAlbum>().SingleOrDefault(a => a.Name.Equals(album.Name)) ?? album; photoAlbum.LastPicturesAdded = DateTime.Now; foreach (FileInfo file in filesToAdd) { Bitmap bmp = new Bitmap(file.FullName); int height = bmp.Height; int width = bmp.Width; bmp.Dispose(); Photo photo = new Photo { PhotoAlbum = photoAlbum, FileName = file.Name, FileSize = file.Length, Height = height, Uploader = uploader, Width = width }; this.Session.Save(photo); } }
/// <summary>Gets the topics for the forum.</summary> /// <param name="forumId">The forum id.</param> /// <param name="pagingParameters">The paging parameters.</param> /// <param name="currentUser">The current user.</param> /// <returns>The topics.</returns> public IEnumerable <Topic> GetTopicsForForum(int forumId, PagingParameters pagingParameters, MediaCommUser currentUser) { this.Logger.Debug("Getting topics for forum with id '{0}' and paging parameters: {1}", forumId, pagingParameters); List <Topic> topics = this.Session.Query <Topic>().Where( t => t.Forum.Id == forumId && !t.ExcludedUsers.Contains(currentUser)).OrderByDescending( t => t.DisplayPriority).ThenByDescending(t => t.LastPostTime).ThenByDescending(t => t.Id).Skip( (pagingParameters.CurrentPage - 1) * pagingParameters.PageSize).Take( pagingParameters.PageSize).ToList(); this.UpdateTopicReadStatus(topics.Where(t => t.LastPostTime > DateTime.Now - this.topicUnreadValidity), currentUser); this.Logger.Debug("Got '{0}' topics", topics.Count()); return(topics); }
/// <summary>Gets the current user.</summary> /// <returns>The current user.</returns> private MediaCommUser GetCurrentUser() { return(this.currentUser ?? (this.currentUser = this.userRepository.GetUserByName(this.User.Identity.Name))); }
/// <summary>Adds the pictures to DB.</summary> /// <param name="filesToAdd">The files to add.</param> /// <param name="album">The album.</param> /// <param name="uploader">The uploader.</param> private void AddPicturesToDB(IEnumerable <FileInfo> filesToAdd, PhotoAlbum album, MediaCommUser uploader) { this.Logger.Debug("Adding {0} photos from the folder to the database. Album: '{1}', Uploader: '{2}'", filesToAdd.Count(), album, uploader); PhotoAlbum photoAlbum = this.Session.Query <PhotoAlbum>().SingleOrDefault( a => a.Name.Equals(album.Name)) ?? album; photoAlbum.LastPicturesAdded = DateTime.Now; this.InvokeTransaction(delegate(ISession session) { foreach (FileInfo file in filesToAdd) { Bitmap bmp = new Bitmap(file.FullName); int height = bmp.Height; int width = bmp.Width; bmp.Dispose(); Photo photo = new Photo { PhotoAlbum = photoAlbum, FileName = file.Name, FileSize = file.Length, Height = height, Uploader = uploader, Width = width }; this.Logger.Debug("Adding photo '{0}' to the database"); session.Save(photo); } }); this.Logger.Debug("Finished adding photos to the database."); }
public void UpdateUser(MediaCommUser user) { this.Session.Update(user); }
/// <summary>Gets the posts for the specified page of the topic.</summary> /// <param name="topicId">The topic ID.</param> /// <param name="pagingParameters">The paging parameters.</param> /// <param name="currentUser">The current user.</param> /// <returns>The posts.</returns> public IEnumerable <Post> GetPostsForTopic(int topicId, PagingParameters pagingParameters, MediaCommUser currentUser) { this.Logger.Debug("Getting posts for topic with id '{0}' and paging parameters: {1}", topicId, pagingParameters); int postsToSkip = (pagingParameters.CurrentPage - 1) * pagingParameters.PageSize; List <Post> posts = this.Session.Query <Post>().Where(p => p.Topic.Id == topicId) .OrderBy(p => p.Created) .Skip(postsToSkip) .Take(pagingParameters.PageSize).ToList(); int lastPage = ((pagingParameters.TotalCount - 1) / pagingParameters.PageSize) + 1; bool isLastPage = pagingParameters.CurrentPage == lastPage; if (isLastPage) { this.InvokeTransaction( s => { TopicRead topicRead = s.Query <TopicRead>().SingleOrDefault( r => r.ReadByUser.Id == currentUser.Id && r.ReadTopic.Id == topicId) ?? new TopicRead { ReadByUser = currentUser, ReadTopic = s.Get <Topic>(topicId) }; topicRead.LastVisit = DateTime.Now; s.SaveOrUpdate(topicRead); }); } this.Logger.Debug("Got {0} posts", posts.Count()); return(posts); }