Esempio n. 1
0
 public void ReplaceRelatedUsers(Context context, List <int> users)
 {
     Address = Address.Replace(
         "[RelatedUsers]",
         Repository.ExecuteTable(
             context: context,
             statements: Rds.SelectMailAddresses(
                 column: Rds.MailAddressesColumn()
                 .OwnerId()
                 .MailAddress(),
                 where : Rds.MailAddressesWhere()
                 .OwnerId_In(users
                             .Distinct()
                             .Where(userId => SiteInfo.User(
                                        context: context,
                                        userId: userId).Id != SiteInfo.AnonymousId)
                             .Select(userId => userId.ToLong()))
                 .OwnerType("Users")))
         .AsEnumerable()
         .GroupBy(o => o["OwnerId"])
         .Select(o => MailAddressUtilities.Get(
                     SiteInfo.UserName(
                         context: context,
                         userId: o.First().Int("OwnerId")),
                     o.First()["MailAddress"].ToString()))
         .Join(";"));
 }
Esempio n. 2
0
        public void Send(Context context, SiteSettings ss, string title, string url, string body)
        {
            var from = MailAddressUtilities.Get(
                context: context,
                userId: context.UserId,
                withFullName: true);

            switch (Type)
            {
            case Types.Mail:
                if (Parameters.Notification.Mail)
                {
                    var mailFrom = new System.Net.Mail.MailAddress(
                        Addresses.BadAddress(from) == string.Empty
                                ? from
                                : Parameters.Mail.SupportFrom);
                    new OutgoingMailModel()
                    {
                        Title = new Title(Prefix + title),
                        Body  = "{0}\r\n{1}".Params(url, body) + (Addresses.FixedFrom(mailFrom)
                                ? "\r\n\r\n{0}<{1}>".Params(mailFrom.DisplayName, mailFrom.Address)
                                : string.Empty),
                        From = mailFrom,
                        To   = Address
                    }.Send(context: context, ss: ss);
                }
                break;

            case Types.Slack:
                if (Parameters.Notification.Slack)
                {
                    new Slack(
                        "*{0}{1}*\n{2}\n{3}".Params(Prefix, title, url, body),
                        from)
                    .Send(Address);
                }
                break;

            case Types.ChatWork:
                if (Parameters.Notification.ChatWork)
                {
                    new ChatWork(
                        "*{0}{1}*\n{2}\n{3}".Params(Prefix, title, url, body),
                        from,
                        Token)
                    .Send(Address);
                }
                break;

            default:
                break;
            }
        }
Esempio n. 3
0
        public string Tooltip(Context context)
        {
            var mailAddress = Parameters.User.IsMailAddressSelectorToolTip()
                ? MailAddressUtilities.Get(
                context: context,
                userId: Id)
                : string.Empty;
            var list = new List <string>()
            {
                Strings.CoalesceEmpty(mailAddress, LoginId),
                UserCode,
                Body
            };

            return(list.Where(o => !o.IsNullOrEmpty()).Join(" "));
        }
Esempio n. 4
0
 public void ReplaceRelatedUsers(IEnumerable <long> users)
 {
     Address = Address.Replace(
         "[RelatedUsers]",
         Rds.ExecuteTable(statements: Rds.SelectMailAddresses(
                              column: Rds.MailAddressesColumn()
                              .OwnerId()
                              .MailAddress(),
                              where : Rds.MailAddressesWhere()
                              .OwnerId_In(users.Distinct())))
         .AsEnumerable()
         .GroupBy(o => o["OwnerId"])
         .Select(o => MailAddressUtilities.Get(
                     SiteInfo.UserName(o.First()["OwnerId"].ToInt()),
                     o.First()["MailAddress"].ToString()))
         .Join(";"));
 }
Esempio n. 5
0
        public void Send(string title, string url, string body)
        {
            var from = MailAddressUtilities.Get(Sessions.UserId(), withFullName: true);

            switch (Type)
            {
            case Types.Mail:
                var mailFrom = new System.Net.Mail.MailAddress(
                    Mails.Addresses.BadAddress(from) == string.Empty
                            ? from
                            : Parameters.Mail.SupportFrom);
                new OutgoingMailModel()
                {
                    Title = new Title(Prefix + title),
                    Body  = "{0}\n{1}".Params(url, body) +
                            (!Parameters.Mail.FixedFrom.IsNullOrEmpty()
                                ? "\n\n{0}<{1}>".Params(mailFrom.DisplayName, mailFrom.Address)
                                : string.Empty),
                    From = mailFrom,
                    To   = Address
                }.Send();
                break;

            case Types.Slack:
                new Slack(
                    "*{0}{1}*\n{2}\n{3}".Params(Prefix, title, url, body),
                    from)
                .Send(Address);
                break;

            case Types.ChatWork:
                new ChatWork(
                    "*{0}{1}*\n{2}\n{3}".Params(Prefix, title, url, body),
                    from,
                    Token)
                .Send(Address);
                break;

            default:
                break;
            }
        }
Esempio n. 6
0
        public void Send(
            Context context,
            SiteSettings ss,
            string title,
            string body,
            Dictionary <Column, string> values = null)
        {
            if (Disabled == true)
            {
                return;
            }
            var from = MailAddressUtilities.Get(
                context: context,
                userId: context.UserId,
                withFullName: true);

            switch (Type)
            {
            case Types.Mail:
                if (Parameters.Notification.Mail)
                {
                    var mailFrom = new System.Net.Mail.MailAddress(
                        Addresses.BadAddress(addresses: from) == string.Empty
                                ? from
                                : Parameters.Mail.SupportFrom);
                    values?.ForEach(data => Address = Address.Replace($"[{data.Key.ColumnName}]",
                                                                      (data.Key.Type == Column.Types.User
                                ? data.Key.MultipleSelections == true
                                    ? data.Value.Deserialize <List <int> >()
                                                                       ?.Where(userId => !SiteInfo.User(
                                                                                   context: context,
                                                                                   userId: userId).Anonymous())
                                                                       .Select(userId => $"[User{userId}]")
                                                                       .Join()
                                    : !SiteInfo.User(
                                                                           context: context,
                                                                           userId: data.Value.ToInt()).Anonymous()
                                            ? $"[User{data.Value}]"
                                            : string.Empty
                                : data.Key.MultipleSelections == true
                                    ? data.Value.Deserialize <List <string> >()
                                                                       ?.Join()
                                    : data.Value)));
                    var to = Addresses.Get(
                        context: context,
                        addresses: Address).Join(",");
                    if (!to.IsNullOrEmpty())
                    {
                        new OutgoingMailModel()
                        {
                            Title = new Title(Prefix + title),
                            Body  = body,
                            From  = mailFrom,
                            To    = to
                        }.Send(context: context, ss: ss);
                    }
                }
                break;

            case Types.Slack:
                if (Parameters.Notification.Slack)
                {
                    new Slack(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}",
                        _username: from)
                    .Send(Address);
                }
                break;

            case Types.ChatWork:
                if (Parameters.Notification.ChatWork)
                {
                    new ChatWork(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}",
                        _username: from,
                        _token: Token)
                    .Send(Address);
                }
                break;

            case Types.Line:
            case Types.LineGroup:
                if (Parameters.Notification.Line)
                {
                    new Line(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}",
                        _username: from,
                        _token: Token)
                    .Send(Address, Type == Types.LineGroup);
                }
                break;

            case Types.Teams:
                if (Parameters.Notification.Teams)
                {
                    new Teams(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}")
                    .Send(Address);
                }
                break;

            default:
                break;
            }
        }
Esempio n. 7
0
        public ControlData ControlData(Context context, SiteSettings ss, bool withType = true)
        {
            switch (Name)
            {
            case "Dept":
                var dept = SiteInfo.Dept(
                    tenantId: context.TenantId,
                    deptId: Id);
                return(DisplayText(
                           context: context,
                           text: Displays.Depts(context: context),
                           name: Id != 0
                            ? dept?.Name
                            : null,
                           title: dept?.Code,
                           withType: withType));

            case "Group":
                var groupModel = Id != 0
                        ? new GroupModel(
                    context: context,
                    ss: SiteSettingsUtilities.GroupsSiteSettings(context: context),
                    groupId: Id)
                        : null;
                return(DisplayText(
                           context: context,
                           text: Displays.Groups(context: context),
                           name: groupModel?.AccessStatus == Databases.AccessStatuses.Selected
                            ? groupModel.GroupName
                            : null,
                           title: null,
                           withType: withType));

            case "User":
                var user = SiteInfo.User(
                    context: context,
                    userId: Id);
                var mailAddress = Parameters.User.IsMailAddressSelectorToolTip()
                        ? MailAddressUtilities.Get(
                    context: context,
                    userId: Id)
                        : string.Empty;
                return(DisplayText(
                           context: context,
                           text: Displays.Users(context: context),
                           name: Id != 0
                            ? user?.Name
                            : null,
                           title: Id != 0
                            ? Strings.CoalesceEmpty(mailAddress, user?.LoginId)
                            : null,
                           withType: withType));

            default:
                var column = ss?.GetColumn(
                    context: context,
                    columnName: Name);
                return(DisplayText(
                           context: context,
                           text: Displays.Column(context: context),
                           name: column?.LabelText,
                           title: column?.LabelTextDefault,
                           withType: withType));
            }
        }
Esempio n. 8
0
        public void Send(Context context, SiteSettings ss, string title, string body)
        {
            if (Disabled == true)
            {
                return;
            }
            var from = MailAddressUtilities.Get(
                context: context,
                userId: context.UserId,
                withFullName: true);

            switch (Type)
            {
            case Types.Mail:
                if (Parameters.Notification.Mail)
                {
                    var mailFrom = new System.Net.Mail.MailAddress(
                        Addresses.BadAddress(addresses: from) == string.Empty
                                ? from
                                : Parameters.Mail.SupportFrom);
                    new OutgoingMailModel()
                    {
                        Title = new Title(Prefix + title),
                        Body  = body,
                        From  = mailFrom,
                        To    = Addresses.Get(
                            context: context,
                            addresses: Address).Join(",")
                    }.Send(context: context, ss: ss);
                }
                break;

            case Types.Slack:
                if (Parameters.Notification.Slack)
                {
                    new Slack(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}",
                        _username: from)
                    .Send(Address);
                }
                break;

            case Types.ChatWork:
                if (Parameters.Notification.ChatWork)
                {
                    new ChatWork(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}",
                        _username: from,
                        _token: Token)
                    .Send(Address);
                }
                break;

            case Types.Line:
            case Types.LineGroup:
                if (Parameters.Notification.Line)
                {
                    new Line(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}",
                        _username: from,
                        _token: Token)
                    .Send(Address, Type == Types.LineGroup);
                }
                break;

            case Types.Teams:
                if (Parameters.Notification.Teams)
                {
                    new Teams(
                        _context: context,
                        _text: $"*{Prefix}{title}*\n{body}")
                    .Send(Address);
                }
                break;

            default:
                break;
            }
        }