Пример #1
0
        public async Task <IActionResult> HandleAsync(HttpContext httpContext, string origin, Form form, IDictionary <Field, string> valuesByFields, IDictionary <string, byte[]> attachmentsByFilenames)
        {
            StringBuilder body = new StringBuilder();

            foreach (KeyValuePair <Field, string> valueByField in valuesByFields)
            {
                body.AppendFormat("<p>{0}: {1}</p>", valueByField.Key.Name.GetLocalizationValue(), valueByField.Value);
            }

            ParametersParser parametersParser = new ParametersParser(form.FormHandlerParameters);
            IEmailSender     emailSender      = httpContext.RequestServices.GetService <IEmailSender>();

            if (emailSender != null)
            {
                string recipientEmails = parametersParser.GetStringParameterValue("RecipientEmails");

                if (!string.IsNullOrEmpty(recipientEmails))
                {
                    foreach (string recipientEmail in recipientEmails.Split(','))
                    {
                        await emailSender.SendEmailAsync(
                            recipientEmail,
                            string.Format("{0} form data", form.Name.GetLocalizationValue()),
                            body.ToString(),
                            attachmentsByFilenames
                            );
                    }
                }
            }

            string redirectUrl = parametersParser.GetStringParameterValue("RedirectUrl");

            if (httpContext.GetConfigurationManager()["Globalization", "SpecifyCultureInUrl"] == "yes")
            {
                return(new RedirectResult($"/{CultureInfo.CurrentCulture.TwoLetterISOLanguageName}{redirectUrl}"));
            }

            return(new RedirectResult(redirectUrl));
        }
Пример #2
0
        public override async Task <dynamic> GetDataAsync(HttpContext httpContext, DataSource dataSource)
        {
            ParametersParser parametersParser = new ParametersParser(dataSource.DataProviderParameters);

            Inclusion <Object>[] inclusions = null;

            if (parametersParser.GetStringParameterValue("RelationType") == "Primary")
            {
                inclusions = new Inclusion <Object>[] {
                    new Inclusion <Object>("Properties.Member"),
                    new Inclusion <Object>("Properties.StringValue.Localizations"),
                    new Inclusion <Object>("ForeignRelations.Primary.Properties.Member"),
                    new Inclusion <Object>("ForeignRelations.Primary.Properties.StringValue.Localizations")
                }
            }
            ;

            else
            {
                inclusions = new Inclusion <Object>[] {
                    new Inclusion <Object>("Properties.Member"),
                    new Inclusion <Object>("Properties.StringValue.Localizations"),
                    new Inclusion <Object>("PrimaryRelations.Foreign.Properties.Member"),
                    new Inclusion <Object>("PrimaryRelations.Foreign.Properties.StringValue.Localizations")
                }
            };

            Object @object = (await httpContext.GetStorage().GetRepository <int, Object, ObjectFilter>().GetAllAsync(
                                  new ObjectFilter(stringValue: new LocalizationFilter(value: new StringFilter(equals: httpContext.Request.GetUrl()))),
                                  inclusions: inclusions
                                  )).FirstOrDefault();

            if (@object == null)
            {
                return(null);
            }

            int relationMemberId = parametersParser.GetIntParameterValue("RelationMemberId");

            if (new ParametersParser(dataSource.DataProviderParameters).GetStringParameterValue("RelationType") == "Primary")
            {
                return(@object.ForeignRelations.Where(r => r.MemberId == relationMemberId).Select(r => this.CreateViewModel(r.Primary)));
            }

            return(@object.PrimaryRelations.Where(r => r.MemberId == relationMemberId).Select(r => this.CreateViewModel(r.Foreign)));
        }
    }