Ejemplo n.º 1
0
        public IActionResult Send()
        {
            StringBuilder body = new StringBuilder();
            Dictionary <string, byte[]> attachments = new Dictionary <string, byte[]>();
            Form          form          = this.Storage.GetRepository <IFormRepository>().WithKey(int.Parse(this.Request.Form["formId"]));
            CompletedForm completedForm = new CompletedForm();

            completedForm.FormId  = form.Id;
            completedForm.Created = DateTime.Now;
            this.Storage.GetRepository <ICompletedFormRepository>().Create(completedForm);
            this.Storage.Save();

            foreach (Field field in this.Storage.GetRepository <IFieldRepository>().FilteredByFormId(form.Id))
            {
                FieldType fieldType = this.Storage.GetRepository <IFieldTypeRepository>().WithKey(field.FieldTypeId);

                if (fieldType.Code == "FileUpload")
                {
                    IFormFile file = this.Request.Form.Files[string.Format("field{0}", field.Id)];

                    if (file != null && !string.IsNullOrEmpty(file.FileName))
                    {
                        string filename = file.FileName;

                        if (!string.IsNullOrEmpty(filename) && filename.Contains("\\"))
                        {
                            filename = filename.Substring(filename.LastIndexOf("\\") + 1);
                        }

                        attachments.Add(filename, this.GetBytesFromStream(file.OpenReadStream()));
                    }
                }

                else
                {
                    string value = this.Request.Form[string.Format("field{0}", field.Id)];

                    body.AppendFormat("<p>{0}: {1}</p>", this.GetLocalizationValue(field.NameId), value);

                    CompletedField completedField = new CompletedField();

                    completedField.CompletedFormId = completedForm.Id;
                    completedField.FieldId         = field.Id;
                    completedField.Value           = value;
                    this.Storage.GetRepository <ICompletedFieldRepository>().Create(completedField);
                }
            }

            this.Storage.Save();
            this.SendEmail(form, body.ToString(), attachments);

            string redirectUrl = form.RedirectUrl;

            if (this.configurationRoot["Globalization:SpecifyCultureInUrl"] == "yes")
            {
                redirectUrl = "/" + CultureInfo.CurrentCulture.TwoLetterISOLanguageName + redirectUrl;
            }

            return(this.Redirect(redirectUrl));
        }
Ejemplo n.º 2
0
 public CompletedFieldViewModel Create(CompletedField completedField)
 {
     return(new CompletedFieldViewModel()
     {
         Id = completedField.Id,
         Field = new FieldViewModelFactory().Create(completedField.Field),
         Value = completedField.Value
     });
 }
 public CompletedFieldViewModel Create(CompletedField completedField)
 {
     return(new CompletedFieldViewModel()
     {
         Id = completedField.Id,
         Field = new FieldViewModelFactory(this.RequestHandler).Create(
             this.RequestHandler.Storage.GetRepository <IFieldRepository>().WithKey(completedField.FieldId)
             ),
         Value = completedField.Value
     });
 }
Ejemplo n.º 4
0
        public IActionResult Send()
        {
            StringBuilder body          = new StringBuilder();
            Form          form          = this.Storage.GetRepository <IFormRepository>().WithKey(int.Parse(this.Request.Form["formId"]));
            CompletedForm completedForm = new CompletedForm();

            completedForm.FormId  = form.Id;
            completedForm.Created = DateTime.Now.ToUnixTimestamp();
            this.Storage.GetRepository <ICompletedFormRepository>().Create(completedForm);
            this.Storage.Save();

            foreach (Field field in this.Storage.GetRepository <IFieldRepository>().FilteredByFormId(form.Id))
            {
                string value = this.Request.Form[string.Format("field{0}", field.Id)];

                // TODO: change the way the localized value is retrieved
                body.AppendFormat(
                    "<p>{0}: {1}</p>",
                    this.Storage.GetRepository <ILocalizationRepository>().FilteredByDictionaryId(field.NameId).First().Value,
                    value
                    );

                CompletedField completedField = new CompletedField();

                completedField.CompletedFormId = completedForm.Id;
                completedField.FieldId         = field.Id;
                completedField.Value           = value;
                this.Storage.GetRepository <ICompletedFieldRepository>().Create(completedField);
            }

            this.Storage.Save();
            this.SendEmail(form, body.ToString());

            // TODO: add RedirectUrl property to the Form class
            string referer = this.Request.Headers["Referer"];

            if (string.IsNullOrEmpty(referer))
            {
                referer = "/";
            }

            return(this.Redirect(referer));
        }
Ejemplo n.º 5
0
        private void ProduceCompletedForms(Form form, IDictionary <Field, string> valuesByFields, IDictionary <string, byte[]> attachmentsByFilenames)
        {
            CompletedForm completedForm = new CompletedForm();

            completedForm.FormId  = form.Id;
            completedForm.Created = DateTime.Now;
            this.Storage.GetRepository <ICompletedFormRepository>().Create(completedForm);
            this.Storage.Save();

            foreach (KeyValuePair <Field, string> valueByField in valuesByFields)
            {
                CompletedField completedField = new CompletedField();

                completedField.CompletedFormId = completedForm.Id;
                completedField.FieldId         = valueByField.Key.Id;
                completedField.Value           = valueByField.Value;
                this.Storage.GetRepository <ICompletedFieldRepository>().Create(completedField);
            }

            this.Storage.Save();
        }
Ejemplo n.º 6
0
        private async Task ProduceCompletedForms(Form form, IDictionary <Field, string> valuesByFields, IDictionary <string, byte[]> attachmentsByFilenames)
        {
            CompletedForm completedForm = new CompletedForm();

            completedForm.FormId  = form.Id;
            completedForm.Created = DateTime.Now;
            this.Storage.GetRepository <int, CompletedForm, CompletedFormFilter>().Create(completedForm);
            await this.Storage.SaveAsync();

            foreach (KeyValuePair <Field, string> valueByField in valuesByFields)
            {
                CompletedField completedField = new CompletedField();

                completedField.CompletedFormId = completedForm.Id;
                completedField.FieldId         = valueByField.Key.Id;
                completedField.Value           = valueByField.Value;
                this.Storage.GetRepository <int, CompletedField, CompletedFieldFilter>().Create(completedField);
            }

            await this.Storage.SaveAsync();
        }