/// <summary> /// Save a new system notification /// </summary> /// <param name="actionUserId">action user id</param> /// <param name="userId">user id</param> /// <param name="value">text value</param> /// <param name="targetURL">target URL</param> /// <param name="templateId">template id</param> /// <param name="elementId">element id</param> /// <param name="session">SQL session</param> /// <returns>true if the notification was created false if not</returns> private static bool SaveSystemNotification(int?actionUserId, int userId, string value, string targetURL, int templateId, int elementId, ISession session) { bool result = false; SystemNotificationRepository notificationRepository = new SystemNotificationRepository(session); notificationRepository.Entity.UserId = userId; notificationRepository.Entity.ActionUserId = actionUserId; notificationRepository.Entity.TemplateId = templateId; notificationRepository.Entity.ElementId = elementId; notificationRepository.Entity.Value = value; notificationRepository.Entity.TargetURL = targetURL; notificationRepository.Entity.Seen = false; notificationRepository.Entity.CreationDate = DateTime.Now; object newId = notificationRepository.Insert(); if (newId != null) { int id = 0; if (int.TryParse(newId.ToString(), out id)) { result = true; } } return(result); }
public JsonResult Crear(int ideaId, string text) { bool result = false; int currentUserId = ((CustomPrincipal)User).UserId; CommentRepository commentRepository = new CommentRepository(SessionCustom); commentRepository.Entity.Text = text; commentRepository.Entity.IdeaId = ideaId; commentRepository.Entity.Active = true; commentRepository.Entity.UserId = currentUserId; commentRepository.Entity.Creationdate = DateTime.Now; int commentId = Convert.ToInt32(commentRepository.Insert()); result = true; IdeaRepository idea = new IdeaRepository(SessionCustom); idea.Entity.IdeaId = ideaId; idea.LoadByKey(); bool update = idea.Entity.UserId.Value == commentRepository.Entity.UserId.Value ? true : false; if (idea.Entity.UserId.Value != commentRepository.Entity.UserId.Value) { Utils.SetUserRewardAction(commentRepository.Entity.UserId.Value, RewardAction.UserActionType.CommentIdea, 21, 21, this.SessionCustom, ControllerContext.HttpContext, true, this.CurrentLanguage); Utils.SetUserRewardAction(idea.Entity.UserId.Value, RewardAction.UserActionType.ReciveComment, 21, int.MaxValue, this.SessionCustom, ControllerContext.HttpContext, update, this.CurrentLanguage); Business.Utilities.Notification.NewNotification(idea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.RECEIVE_IDEA_COMMENT, currentUserId, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, commentId, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage); } else { Utils.SetUserRewardAction(commentRepository.Entity.UserId.Value, RewardAction.UserActionType.CommentIdea, 21, 0, this.SessionCustom, ControllerContext.HttpContext, true, this.CurrentLanguage); Utils.SetUserRewardAction(idea.Entity.UserId.Value, RewardAction.UserActionType.ReciveComment, 21, 0, this.SessionCustom, ControllerContext.HttpContext, update, this.CurrentLanguage); } // hilo notificaciones de usuarios relacionados Business.Utilities.Notification.StartRelatedContentUser(commentRepository.Entity.UserId.Value, idea.Entity.IdeaId.Value, null, Domain.Entities.Basic.SystemNotificationType.RECEIVE_IDEA_RELATED_COMMENT, currentUserId, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, commentId, null, null, null, this.HttpContext, this.CurrentLanguage); if (idea.IsIdeaInTop10(idea.Entity.IdeaId.Value)) { SystemNotificationRepository notification = new SystemNotificationRepository(SessionCustom); int count = notification.SystemNotificationCount(idea.Entity.UserId.Value, (int)Domain.Entities.Basic.SystemNotificationType.IDEA_TOP_10, idea.Entity.IdeaId.Value); if (count == 0) { Business.Utilities.Notification.NewNotification(idea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.IDEA_TOP_10, null, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, idea.Entity.IdeaId.Value, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage); } } if (idea.IsIdeaInTop5Home(idea.Entity.IdeaId.Value)) { SystemNotificationRepository notification = new SystemNotificationRepository(SessionCustom); int count = notification.SystemNotificationCount(idea.Entity.UserId.Value, (int)Domain.Entities.Basic.SystemNotificationType.POPULAR_IDEA_TOP_5, idea.Entity.IdeaId.Value); if (count == 0) { Business.Utilities.Notification.NewNotification(idea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.POPULAR_IDEA_TOP_5, null, string.Concat("/", idea.Entity.Friendlyurlid), idea.Entity.ContentId, idea.Entity.IdeaId.Value, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage); } } Business.UserRelation.SaveRelationAction(((CustomPrincipal)User).UserId, idea.Entity.UserId.Value, commentId, "comment", this.SessionCustom); return(this.Json(new { result = result })); }
public SystemNotificationBusiness(string connectionString) : base(connectionString) { rep = new SystemNotificationRepository(Connection); }
/// <summary> /// Fill a front end information /// </summary> /// <param name="key">search criteria</param> /// <param name="userId">current user ID</param> public void BindInfo(int key, int?userId) { ContentRepository objcont = new ContentRepository(this.session); this.Metatags = new List <KeyValuePair <KeyValue, KeyValue> >(); if (this.type == Type.Content) { objcont.Entity.ContentId = key; objcont.LoadByKey(); if (objcont.Entity.ContentId == null) { this.Outcome = Result.NotFound; } else { this.Section = this.sections.Find(t => t.SectionId == objcont.Entity.SectionId); if (Section != null) { this.Content = objcont.Entity; this.Layout = this.Section.Layout; this.Template = objcont.Entity.Template; this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("name", "title"), new Domain.Entities.KeyValue("content", objcont.Entity.Name))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("name", "description"), new Domain.Entities.KeyValue("content", objcont.Entity.Shortdescription))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:title"), new Domain.Entities.KeyValue("content", objcont.Entity.Name))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:description"), new Domain.Entities.KeyValue("content", objcont.Entity.Shortdescription))); if (HttpContext.Current != null) { FileattachRepository fileRepository = new FileattachRepository(new SqlSession()); fileRepository.Entity.ContentId = objcont.Entity.ContentId; Fileattach file = fileRepository.GetAll().FirstOrDefault(t => t.Type == Domain.Entities.Fileattach.TypeFile.Video); string fileName = string.Empty; if (file != null) { fileName = string.Concat(file.Name, "v=", file.Filename); } string siteUrlRoot = ("http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath).TrimEnd('/'); Domain.Entities.FrontEnd.Video video = Business.Utils.GetVideoFromUrl(fileName); string picture = siteUrlRoot + "/1024.png"; if (!string.IsNullOrEmpty(objcont.Entity.Image)) { picture = siteUrlRoot + "/files/" + objcont.Entity.ContentId + "/" + objcont.Entity.Image; } else if (video != null && video.Type == "youtube") { picture = "http://img.youtube.com/vi/" + video.ID + "/default.jpg"; } this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:image"), new Domain.Entities.KeyValue("content", picture))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:url"), new Domain.Entities.KeyValue("content", ("http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath).TrimEnd('/') + "/" + objcont.Entity.Frienlyname))); } this.Outcome = Result.Ok; this.Detail = this.GetDetail(this.GetNameType(objcont.Entity.Template), objcont.Entity.ContentId, userId, this.language.LanguageId); this.DeepFollower = Utils.GetDeepFollowerFrontEnd(this.sections, this.Section.SectionId.Value, this.Content, this.language); objcont.Entity.Views++; objcont.Update(); } else { this.Outcome = Result.NotFound; } } } else if (this.type == Type.Idea) { IdeaRepository objidea = new IdeaRepository(this.session); objidea.Entity.IdeaId = key; objidea.LoadByKey(); if (objidea.Entity.ContentId == null) { this.Outcome = Result.NotFound; } else { objcont.Entity.ContentId = objidea.Entity.ContentId; objcont.LoadByKey(); this.Section = this.sections.Find(t => t.SectionId == objcont.Entity.SectionId); if (Section != null) { this.Idea = objidea.Entity; this.Layout = this.Section.Layout; this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("name", "title"), new Domain.Entities.KeyValue("content", objcont.Entity.Name))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("name", "description"), new Domain.Entities.KeyValue("content", objcont.Entity.Shortdescription))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:title"), new Domain.Entities.KeyValue("content", objcont.Entity.Name))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:description"), new Domain.Entities.KeyValue("content", objcont.Entity.Shortdescription))); string siteUrlRoot = ("http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath).TrimEnd('/'); Domain.Entities.FrontEnd.Video video = Business.Utils.GetVideoFromUrl(objidea.Entity.Video); string picture = siteUrlRoot + "/1024.png"; if (!string.IsNullOrEmpty(objidea.Entity.Image)) { picture = siteUrlRoot + "/files/ideas/" + objidea.Entity.Image; } else if (video != null && video.Type == "youtube") { picture = "http://img.youtube.com/vi/" + video.ID + "/default.jpg"; } this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:image"), new Domain.Entities.KeyValue("content", picture))); FriendlyurlRepository url = new FriendlyurlRepository(this.session); url.Entity.Id = key; url.Entity.Type = Friendlyurl.FriendlyType.Idea; url.Load(); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:url"), new Domain.Entities.KeyValue("content", ("http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath).TrimEnd('/') + "/" + url.Entity.Friendlyurlid))); this.Outcome = Result.Ok; this.Detail = this.GetDetail(this.GetNameType(objcont.Entity.Template), objcont.Entity.ContentId, userId, this.language.LanguageId); this.DeepFollower = Utils.GetDeepFollowerFrontEnd(this.sections, this.Section.SectionId.Value, this.Content, this.language); objidea.Entity.Views++; objidea.Update(); if (objidea.IsIdeaInTop10(objidea.Entity.IdeaId.Value)) { SystemNotificationRepository notification = new SystemNotificationRepository(this.session); int count = notification.SystemNotificationCount(objidea.Entity.UserId.Value, (int)Domain.Entities.Basic.SystemNotificationType.IDEA_TOP_10, objidea.Entity.IdeaId.Value); if (count == 0) { Business.Utilities.Notification.NewNotification(objidea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.IDEA_TOP_10, null, string.Concat("/", objidea.Entity.Friendlyurlid), objidea.Entity.ContentId, objidea.Entity.IdeaId.Value, null, null, null, this.session, this.context, this.language); } } if (objidea.IsIdeaInTop5Home(objidea.Entity.IdeaId.Value)) { SystemNotificationRepository notification = new SystemNotificationRepository(this.session); int count = notification.SystemNotificationCount(objidea.Entity.UserId.Value, (int)Domain.Entities.Basic.SystemNotificationType.POPULAR_IDEA_TOP_5, objidea.Entity.IdeaId.Value); if (count == 0) { Business.Utilities.Notification.NewNotification(objidea.Entity.UserId.Value, null, Domain.Entities.Basic.SystemNotificationType.POPULAR_IDEA_TOP_5, null, string.Concat("/", objidea.Entity.Friendlyurlid), objidea.Entity.ContentId, objidea.Entity.IdeaId.Value, null, null, null, this.session, this.context, this.language); } } } else { this.Outcome = Result.NotFound; } } } else { this.Section = this.sections.Find(t => t.SectionId == key); if (this.Section == null) { this.Outcome = Result.NotFound; } else { this.Layout = this.Section.Layout; this.Template = this.Section.Template; this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("name", "title"), new Domain.Entities.KeyValue("content", this.Section.Name))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("name", "description"), new Domain.Entities.KeyValue("content", this.Section.Description))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:title"), new Domain.Entities.KeyValue("content", this.Section.Name))); this.Metatags.Add( new KeyValuePair <Domain.Entities.KeyValue, Domain.Entities.KeyValue>( new Domain.Entities.KeyValue("property", "og:description"), new Domain.Entities.KeyValue("content", this.Section.Description))); this.Outcome = Result.Ok; this.Detail = this.GetDetail(this.GetNameType(this.Section.Template), this.Section.SectionId, userId, this.language.LanguageId); this.DeepFollower = Utils.GetDeepFollowerFrontEnd(this.sections, this.Section.SectionId.Value, null, this.language); } } }