Exemplo n.º 1
0
        private async Task HandleRequest(DomainClasses.Entities.FormScheme formScheme, FormSubmitRequest request)
        {
            var form = new DomainClasses.Entities.Form()
            {
                Fields = new List <Field>(), FormSchemeId = formScheme.Id
            };

            SaveDataFields(formScheme, request, form);
            SaveFileFields(formScheme, request, form);
            await BaseBeforeAddAsync(form, request.RequestOwner);

            await _formDataSrv.AddAsync(form);

            await BaseAfterAddAsync(form, request.RequestOwner);
        }
Exemplo n.º 2
0
        private bool HasRequestRequiredFileds(DomainClasses.Entities.FormScheme formScheme, FormSubmitRequest request)
        {
            var requiredProps = formScheme.FieldDefenitions.Where(x => x.IsRequired).Select(x => x.Handle);
            var requestProps  = request.Form.AllKeys.ToList();

            requestProps.AddRange(request.Files.AllKeys);
            var @is = true;

            foreach (var prop in requiredProps)
            {
                if (!requestProps.Contains(prop))
                {
                    @is = false;
                }
            }
            return(@is);
        }
Exemplo n.º 3
0
        private bool AreAllFormFieldsValid(DomainClasses.Entities.FormScheme formScheme, FormSubmitRequest request)
        {
            bool @is = true;

            foreach (string prop in request.Form)
            {
                var fd = formScheme.FieldDefenitions.FirstOrDefault(x => x.Handle == prop);
                if (fd == null)
                {
                    continue;
                }
                if (!_fieldFactoryPrvider.GetFieldFactory(fd.Type).IsValidForField(request.Form[prop], fd.MetaData))
                {
                    @is = false;
                }
            }
            return(@is);
        }
Exemplo n.º 4
0
 private void SaveDataFields(DomainClasses.Entities.FormScheme formScheme, FormSubmitRequest request,
                             DomainClasses.Entities.Form form)
 {
     foreach (string prop in request.Form)
     {
         var fd = formScheme.FieldDefenitions.FirstOrDefault(x => x.Handle == prop);
         if (fd == null)
         {
             continue;
         }
         form.Fields.Add(new Field()
         {
             FieldDefenitionId = fd.Id,
             RawValue          =
                 _fieldFactoryPrvider.GetFieldFactory(fd.Type).CreateNew(fd.Title, request.Form[prop], fd.MetaData).Value ?? fd.DefaultValue,
         });
     }
 }
Exemplo n.º 5
0
        private void SaveFileFields(DomainClasses.Entities.FormScheme formScheme, FormSubmitRequest request,
                                    DomainClasses.Entities.Form form)
        {
            foreach (string prop in request.Files)
            {
                var file = request.Files[prop];
                var fd   = formScheme.FieldDefenitions.FirstOrDefault(x => x.Handle == prop);
                if (fd == null)
                {
                    continue;
                }
                var fileSaveRes = _fileManager.Save(file,
                                                    _formsBaseFolderPath + $"/{formScheme.Handle}/" + file.FileName);
                var data = new FileFieldDataWrapper(file, fileSaveRes.SavedFilePath, fileSaveRes.SavedFileName);

                form.Fields.Add(new Field()
                {
                    FieldDefenitionId = fd.Id,
                    RawValue          = _fieldFactoryPrvider.GetFieldFactory(fd.Type).CreateNew(fd.Title, data, fd.MetaData).Value ?? fd.DefaultValue,
                });
            }
        }
Exemplo n.º 6
0
 private bool AreAllFieldsValid(DomainClasses.Entities.FormScheme formScheme, FormSubmitRequest request)
 {
     return(AreAllFormFieldsValid(formScheme, request) && AreAllFileFieldsValid(formScheme, request));
 }