Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <summary>
        /// gets the home of content according to identifier
        /// </summary>
        /// <param name="id">identifier of content</param>
        /// <returns>returns the result to action</returns>
        public ActionResult Index(int id)
        {
            SetLabel();
            bool versus = false;
            FrontEndManagement   objman     = new FrontEndManagement(SessionCustom, HttpContext, FrontEndManagement.Type.Content, CurrentLanguage);
            BannerRepository     banner     = new BannerRepository(SessionCustom);
            IdeaRepository       idea       = new IdeaRepository(SessionCustom);
            UserAnswerRepository userAnswer = new UserAnswerRepository(SessionCustom);
            bool voted = false;

            idea.Entity.ContentId = id;

            int?currentUserId = null;

            if (User.Identity.IsAuthenticated)
            {
                currentUserId = ((CustomPrincipal)User).UserId;
                objman.BindInfo(id, currentUserId.Value);
                versus = Business.Utils.CheckVersus(((CustomPrincipal)User).UserId, id, this.SessionCustom);
                voted  = userAnswer.CheckUserVoted(((CustomPrincipal)User).UserId, id, null);
            }
            else
            {
                objman.BindInfo(id, null);
                versus = true;
            }

            ViewBag.CurrentUserId = currentUserId;

            if (!objman.Content.Active.Value)
            {
                return(this.Redirect("~/" + objman.Section.Friendlyname));
            }

            if (objman.Outcome == FrontEndManagement.Result.Ok)
            {
                ViewBag.Ideas = idea.GetAll();
                return(this.View(
                           objman.Template,
                           new Models.FEContenido()
                {
                    UserPrincipal = CustomUser,
                    PageTitle = string.Format("{0} | {1}", ConfigurationManager.AppSettings["TitleHome"], objman.Content.Name),
                    Content = objman.Content,
                    Section = objman.Section,
                    Layout = objman.Layout + ".cshtml",
                    Entity = objman.Detail,
                    MetaTags = objman.Metatags,
                    Banners = banner.GetBannersBySection(objman.Section.SectionId.Value, CurrentLanguage.LanguageId.Value),
                    DeepFollower = objman.DeepFollower,
                    CurrentLanguage = CurrentLanguage,
                    IdeasCountAll = idea.IdeasCountAll(),
                    Versus = versus,
                    Voted = voted
                }));
            }
            else if (objman.Outcome == FrontEndManagement.Result.NotFound)
            {
                return(this.View(
                           "Mensaje",
                           new FEMessage()
                {
                    PageTitle = "Recurso no encontrado",
                    UserPrincipal = CustomUser,
                    Banners = banner.GetBannersBySection(0, CurrentLanguage.LanguageId.Value),
                    Title = "Recurso no encontrado",
                    Description = "Recurso no encontrado",
                    Message = Resources.Extend.Messages.RESOURCE_NOT_FOUND,
                    CurrentLanguage = CurrentLanguage
                }));
            }
            else
            {
                return(this.View(
                           "Mensaje",
                           new FEMessage()
                {
                    PageTitle = "Sistema no disponible",
                    UserPrincipal = CustomUser,
                    Banners = banner.GetBannersBySection(0, CurrentLanguage.LanguageId.Value),
                    Title = "Sistema no disponible",
                    Description = "Sistema no disponible",
                    Message = Resources.Extend.Messages.SYSTEM_ERROR,
                    CurrentLanguage = CurrentLanguage
                }));
            }
        }
Exemple #3
0
        public ActionResult Index(int id)
        {
            SetLabel();
            FrontEndManagement objman = new FrontEndManagement(SessionCustom, HttpContext, FrontEndManagement.Type.Content, CurrentLanguage);
            int?currentUserId         = null;

            if (User.Identity.IsAuthenticated)
            {
                currentUserId = ((CustomPrincipal)User).UserId;
                objman.BindInfo(id, currentUserId);
                ViewBag.CurrentUserId = currentUserId;
            }
            else
            {
                objman.BindInfo(id, null);
            }

            IdeaRepository idea = new IdeaRepository(SessionCustom);

            BlogEntryRepository blog = new BlogEntryRepository(SessionCustom);

            blog.Entity.ContentId = id;
            blog.LoadByKey();

            ContentRepository content = new ContentRepository(SessionCustom);

            content.Entity.ContentId = blog.Entity.ContentId;
            content.LoadByKey();

            if (content.Entity.UserId.HasValue)
            {
                // blog owner
                ViewBag.IdeaOwner = content.Entity.UserId.Value == currentUserId;
            }

            int total = 0;
            CommentRepository comment = new CommentRepository(SessionCustom);
            List <Domain.Entities.FrontEnd.CommentsPaging> comments = comment.CommentsPagingContent(1, 6, out total, id);

            FileattachRepository fileRepository = new FileattachRepository(SessionCustom);

            fileRepository.Entity.ContentId = content.Entity.ContentId;
            Fileattach file = fileRepository.GetAll().FirstOrDefault(t => t.Type == Domain.Entities.Fileattach.TypeFile.Video);

            if (file != null)
            {
                content.Entity.Video = file.Filename;
            }

            return(this.View(
                       "IndexNivel3",
                       new Models.FEBlogEntry()
            {
                UserPrincipal = CustomUser,
                Entity = blog.Entity,
                CollComments = comments,
                ObjContent = content.Entity,
                MetaTags = objman.Metatags,
                CurrentLanguage = CurrentLanguage,
                CommentCount = total,
                IdeasCountAll = idea.IdeasCountAll()
            }));
        }