/// <summary> /// obtains the EmailNotification detail /// </summary> /// <param name="mod">identifier of module</param> /// <param name="id">identifier of section</param> /// <returns>returns the result to action</returns> public ActionResult Detail(int mod, int id) { ContentManagement objcontentman = new ContentManagement(SessionCustom, HttpContext); ContentRepository objcontent = new ContentRepository(SessionCustom); EmailNotificationTemplateRepository objnotification = new EmailNotificationTemplateRepository(SessionCustom); FileattachRepository objfiles = new FileattachRepository(SessionCustom); TagRepository objtag = new TagRepository(SessionCustom); SectionRepository objsection = new SectionRepository(SessionCustom); TemplateRepository objtemplate = new TemplateRepository(SessionCustom); TagFacade tagFacade = new TagFacade(); objtemplate.Entity.Type = 0; objnotification.Entity.ContentId = objfiles.Entity.ContentId = objcontent.Entity.ContentId = id; objnotification.LoadByKey(); objcontent.LoadByKey(); IEnumerable <Tag> SelectedTags = objtag.GetTagbycontent(id); this.ViewBag.SelectedTags = string.Join("|", SelectedTags.Select(t => t.TagId)); this.ViewBag.NewsTags = string.Empty; return(this.View( "Index", new EmailNotificationTemplateModel() { UserPrincipal = this.CustomUser, ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext), Module = this.Module, ListFiles = objfiles.GetAllReadOnly(), EmailNotificationTemplate = objnotification.Entity, IContent = objcontent.Entity, Templates = objtemplate.GetAll().Select(t => t.TemplateId), ListContent = objcontent.GetContentRelation(CurrentLanguage.LanguageId.Value), ListTags = SelectedTags, DeepFollower = Business.Utils.GetDeepFollower(objsection.GetAll(), objcontent.Entity.SectionId.Value), CurrentLanguage = this.CurrentLanguage, Tags = tagFacade.GetAll().Select(t => new SelectListItem { Text = t.Name, Value = t.TagId.ToString() }) })); }
public ActionResult Create(EmailNotificationTemplateModel model, HttpPostedFileBase contentImage, List <string> videoyoutube, string existingTags, string newTags) { EmailNotificationTemplateRepository objnotification = new EmailNotificationTemplateRepository(this.SessionCustom); ContentManagement objcontent = new ContentManagement(this.SessionCustom, HttpContext); try { objcontent.ContentImage = contentImage; objcontent.CollVideos = videoyoutube; this.SessionCustom.Begin(); model.IContent.LanguageId = CurrentLanguage.LanguageId; objcontent.ContentInsert(model.IContent); objnotification.Entity = model.EmailNotificationTemplate; objnotification.Entity.ExistingTags = !string.Empty.Equals(existingTags) ? existingTags : null; objnotification.Entity.NewTags = !string.Empty.Equals(newTags) ? newTags : null; if (objnotification.Entity.ContentId != null) { objnotification.Update(); this.InsertAudit("Update", this.Module.Name + " -> " + model.IContent.Name); } else { if (!string.IsNullOrEmpty(Request.Form["TempFiles"])) { string[] files = Request.Form["TempFiles"].Split(','); if (files.Length > 0) { if (!Directory.Exists(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\"))) { Directory.CreateDirectory(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\")); } } foreach (var item in files) { string filep = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item)); if (System.IO.File.Exists(filep)) { string filedestin = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item)); System.IO.File.Move(filep, Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\" + Path.GetFileName(item))); } } } objnotification.Entity.ContentId = objcontent.ObjContent.ContentId; objnotification.Insert(); this.InsertAudit("Insert", this.Module.Name + " -> " + model.IContent.Name); } this.SessionCustom.Commit(); } catch (Exception ex) { SessionCustom.RollBack(); Utils.InsertLog( this.SessionCustom, "Error" + this.Module.Name, ex.Message + " " + ex.StackTrace); } if (Request.Form["GetOut"] == "0") { return(this.RedirectToAction("Index", "Content", new { mod = Module.ModulId })); } else { return(this.RedirectToAction("Detail", "EmailNotification", new { mod = Module.ModulId, id = objnotification.Entity.ContentId })); } }
/// <summary> /// Creates a new email or system notification /// </summary> /// <param name="targetUserId">target user id</param> /// <param name="emailType">email notification type</param> /// <param name="systemType">system notification type</param> /// <param name="actionUserId">action user id</param> /// <param name="url">target URL</param> /// <param name="processId">process id</param> /// <param name="elementId">element id</param> /// <param name="reason">text reason</param> /// <param name="rank">user rank</param> /// <param name="previousRank">user previous rank</param> /// <param name="session">SQL session</param> /// <param name="context">HTTP context</param> /// <param name="language">current language object</param> /// <returns>true if the notification was created false if not</returns> public static bool NewNotification( int targetUserId, Domain.Entities.Basic.EmailNotificationType?emailType, Domain.Entities.Basic.SystemNotificationType?systemType, int?actionUserId, string url, int?processId, int elementId, string reason, string rank, string previousRank, ISession session, HttpContextBase context, Domain.Entities.Language language) { //// i. [yo/], nombre del usuario que recibe la notificación. //// ii. [usuario/], nombre del usuario que realiza la acción. //// iii. [url]html[/url], vincula la selección al contenido de la notificación. //// iv. [tipo/], muestra el tipo del proceso (reto o pregunta). //// v. [proceso/], muestra el nombre del reto o pregunta. //// vi. [n/], muestra el valor numérico configurado. //// vii. [rango/], muestra el rango del usuario. //// viii.[rango-anterior/], muestra el rango anterior del usuario string targetName = null, targetEmail = null, actionName = null, processType = null, processName = null, subject = null, senderName = null; int userlanguage = 0; UserRepository userRepository = new UserRepository(session); userRepository.Entity.UserId = targetUserId; userRepository.LoadByKey(); userlanguage = userRepository.Entity.LanguageId.Value; targetName = userRepository.Entity.Names; targetEmail = userRepository.Entity.Email; bool targetActive = userRepository.Entity.Active.Value; bool result = false; if (targetActive) { if (actionUserId.HasValue) { userRepository.Entity.UserId = actionUserId; userRepository.LoadByKey(); actionName = userRepository.Entity.Names; } else { actionName = "Ciudadano"; } if (processId.HasValue) { FrontEndManagement objman = new FrontEndManagement(session, context, FrontEndManagement.Type.Content, language); objman.BindInfo(processId.Value, targetUserId); processName = objman.Content.Name; if (objman.Detail is Business.FrontEnd.Question) { Business.FrontEnd.Question detail = (Business.FrontEnd.Question)objman.Detail; switch (detail.ObjQuestion.Type) { case Domain.Entities.Question.TypeQuestion.Abierta: processType = "Pregunta Abierta"; break; case Domain.Entities.Question.TypeQuestion.Seleccion_Multiple: processType = "Seleccion Multiple"; break; case Domain.Entities.Question.TypeQuestion.Ubicacion: processType = "Ubicacion"; break; } } else if (objman.Detail is Business.FrontEnd.Challenge) { Business.FrontEnd.Challenge detail = (Business.FrontEnd.Challenge)objman.Detail; switch (detail.ObjChallenge.Type) { case Domain.Entities.Challenge.TypeChallenge.Participacion_Ciudadana: processType = "Participacion ciudadana"; break; case Domain.Entities.Challenge.TypeChallenge.Reto_Ciudad: processType = "Reto ciudad"; break; } } } StringBuilder builder = new StringBuilder(); if (systemType.HasValue) { SystemNotificationTemplateRepository notificationRepository = new SystemNotificationTemplateRepository(session); notificationRepository.Entity.ContentId = (int)systemType; notificationRepository.LoadByKey(); if (userlanguage == (int)Domain.Entities.Enums.LanguageEnum.Spanish) { builder.Append(notificationRepository.Entity.Description); } else { builder.Append(notificationRepository.Entity.DescriptionIngles); } } else if (emailType.HasValue) { EmailNotificationTemplateRepository notificationRepository = new EmailNotificationTemplateRepository(session); notificationRepository.Entity.ContentId = (int)emailType; notificationRepository.LoadByKey(); senderName = notificationRepository.Entity.SenderName; if (userlanguage == (int)Domain.Entities.Enums.LanguageEnum.Spanish) { builder.Append(notificationRepository.Entity.Description); } else { builder.Append(notificationRepository.Entity.DescriptionIngles); } ContentRepository contentRepository = new ContentRepository(session); contentRepository.Entity.ContentId = (int)emailType; contentRepository.LoadByKey(); if (userlanguage == (int)Domain.Entities.Enums.LanguageEnum.Spanish) { subject = contentRepository.Entity.Shortdescription; } else { subject = contentRepository.Entity.ShortdescriptionIngles; } } builder.Replace("[yo/]", targetName) .Replace("[usuario/]", actionName) .Replace("[tipo/]", processType) .Replace("[proceso/]", processName) .Replace("[url]", string.Concat("<a href='", url, "'>")) .Replace("[/url]", string.Concat("</a>")) .Replace("[url/]", string.Concat("<a href='", url, "'>", url, "</a>")) .Replace("[razon/]", reason) .Replace("[rango/]", rank) .Replace("[rango-anterior/]", previousRank); ////.Replace("[n/]", number) biene desde base de datos solo para unos pocos de email if (systemType.HasValue) { result = SaveSystemNotification(actionUserId, targetUserId, builder.ToString(), url, (int)systemType, elementId, session); } else if (emailType.HasValue) { bool send = false; bool token = false; string keyWord = string.Empty; string keyValue = string.Empty; switch (emailType) { case Domain.Entities.Basic.EmailNotificationType.RECEIVE_N_IDEA_LIKE: keyWord = "send-receive-n-idea-like"; keyValue = "value-receive-n-idea-like"; token = true; break; case Domain.Entities.Basic.EmailNotificationType.NEW_PROCESS: keyWord = "send-new-process"; token = true; break; case Domain.Entities.Basic.EmailNotificationType.FINISHING_PROCESS: keyWord = "send-finishing-process"; keyValue = "value-finishing-process"; token = true; break; case Domain.Entities.Basic.EmailNotificationType.FINISHED_PROCESS: keyWord = "send-finished-process"; token = true; break; case Domain.Entities.Basic.EmailNotificationType.IDEA_BLOCKED: keyWord = "send-idea-blocked"; token = true; break; case Domain.Entities.Basic.EmailNotificationType.USER_LEAVE_ADMIN: case Domain.Entities.Basic.EmailNotificationType.USER_LEAVE_USER: case Domain.Entities.Basic.EmailNotificationType.ADMIN_KICKOUT_ADMIN: case Domain.Entities.Basic.EmailNotificationType.ADMIN_KICKOUT_USER: case Domain.Entities.Basic.EmailNotificationType.PROMOTION: case Domain.Entities.Basic.EmailNotificationType.POSTULATESTORY: case Domain.Entities.Basic.EmailNotificationType.PUBLICATEDESTORY: case Domain.Entities.Basic.EmailNotificationType.REJECTEDSTORY: send = true; break; } if (!send) { UserSettingRepository setting = new UserSettingRepository(session); setting.Entity.UserId = targetUserId; setting.Entity.KeyWord = keyWord; setting.Load(); send = Convert.ToBoolean(setting.Entity.Value); if (send && !string.IsNullOrEmpty(keyValue) && !string.IsNullOrEmpty(targetEmail)) { send = false; setting.Entity = new Domain.Entities.UserSetting(); setting.Entity.UserId = targetUserId; setting.Entity.KeyWord = keyValue; setting.Load(); int value = 0; if (int.TryParse(setting.Entity.Value, out value) && value != 0) { if (emailType == Domain.Entities.Basic.EmailNotificationType.RECEIVE_N_IDEA_LIKE) { IdeaRepository idea = new IdeaRepository(session); idea.Entity.IdeaId = elementId; idea.LoadByKey(); if (value == idea.Entity.Likes) { builder.Replace("[n/]", value.ToString()); send = true; } } else if (emailType == Domain.Entities.Basic.EmailNotificationType.FINISHING_PROCESS || emailType == Domain.Entities.Basic.EmailNotificationType.FINISHED_PROCESS) { // ya biene validado desde el automatic builder.Replace("[n/]", value.ToString()); send = true; } } } } if (send && !string.IsNullOrEmpty(targetEmail)) { string key = string.Empty; if (token) { key = GetNotificationToken(targetUserId, emailType.Value, session); } result = SendEmailNotification(builder.ToString(), subject, senderName, targetUserId, targetEmail, url, key, session); } } } return(result); }