public async Task Email(FieldsChangedEmail model)
        {
            var projectEmailEnabled = model.GetEmailEnabled();

            if (!projectEmailEnabled)
            {
                return;
            }

            var recipients = model
                             .GetRecipients()
                             .Select(r => new RecepientData(
                                         r.GetDisplayName(),
                                         r.Email,
                                         new Dictionary <string, string> {
                { ChangedFieldsKey, GetChangedFieldsInfoForUser(model, r) }
            }))
                             .Where(r => !string.IsNullOrEmpty(r.RecipientSpecificValues[ChangedFieldsKey]))
                             //don't email if no changes are visible to user rights
                             .ToList();

            string Target(bool forMessageBody) => model.IsCharacterMail
                ? $@"персонаж{(forMessageBody ? "a" : "")}  {model.Character.CharacterName}"
                : $"заявк{(forMessageBody ? "и" : "a")} {model.Claim?.Name} {(forMessageBody ? $", игрок {model.Claim?.Player.GetDisplayName()}" : "")}";


            var linkString = _uriService.Get(model.GetLinkable());

            if (recipients.Any())
            {
                var text = $@"{StandartGreeting()},
Данные {Target(true)} были изменены. Новые значения:

{MessageService.GetUserDependentValue(ChangedFieldsKey)}

Для просмотра всех данных перейдите на страницу {(model.IsCharacterMail ? "персонажа" : "заявки")}: {linkString}

{model.Initiator.GetDisplayName()}

";
                //All emails related to claim should have the same title, even if the change was made to a character
                Claim claim = model.IsCharacterMail ? model.Character.ApprovedClaim : model.Claim;



                var subject = claim != null
                    ? model.GetClaimEmailTitle(claim)
                    : $"{model.ProjectName}: {Target(false)}";

                await MessageService.SendEmails(subject,
                                                new MarkdownString(text),
                                                model.Initiator.ToRecepientData(),
                                                recipients);
            }
        }
Beispiel #2
0
        public async Task Email(FieldsChangedEmail model)
        {
            var projectEmailEnabled = model.GetEmailEnabled();

            if (!projectEmailEnabled)
            {
                return;
            }

            IList <MailRecipient> recipients = model
                                               .GetRecipients()
                                               .Select(r => new MailRecipient(
                                                           r,
                                                           new Dictionary <string, string> {
                { changedFieldsKey, GetChangedFieldsInfoForUser(model, r) }
            }))
                                               .Where(r => !string.IsNullOrEmpty(r.RecipientSpecificValues[changedFieldsKey]))
                                               //don't email if no changes are visible to user rights
                                               .ToList();

            Func <bool, string> target = (forMessageBody) => model.IsCharacterMail
        ? $@"персонаж{(forMessageBody ? "a" : "")}  {model.Character.CharacterName}"
        : $"заявк{(forMessageBody ? "и" : "a")} {model.Claim.Name} {(forMessageBody ? $", игрок {model.Claim.Player.DisplayName}" : "")}";


            string linkString = model.IsCharacterMail
        ? _uriService.Get(model.Character)
        : _uriService.Get(model.Claim);

            if (recipients.Any())
            {
                await SendEmail(recipients, $"{model.ProjectName}: {target(false)}",
                                $@"Добрый день, {MailGunExts.MailGunRecipientName},
Данные {target(true)} были изменены. Новые значения:

{MailGunExts.GetUserDependentValue(changedFieldsKey)}

Для просмотра всех данных перейдите на страницу {(model.IsCharacterMail ? "персонажа" : "заявки")}: {linkString}

{model.Initiator.DisplayName}

", model.Initiator.ToRecipient());
            }
        }