Esempio n. 1
0
        public override void Render(Context context, TextWriter result)
        {
            try
            {
                var product = context[_product] as ProductLiquidAdapter;
                var fd      = context[_fd] as FieldDefenitionLiquidVeiwModel;
                if (product is null)
                {
                    result.Write("خطا عدم دسترسی به محصول درون قالب  {render_field} !");
                    return;
                }
                if (fd is null)
                {
                    result.Write("خطا عدم دسترسی به تعریف فیلد درون قالب  {render_field} !");
                    return;
                }
                var field = product.Fields.FirstOrDefault(x => x.FieldDefenitionId == fd.Id);
                if (field is null)
                {
                    if (fd.IsRequired)
                    {
                        result.Write($"فیلد اجباری بدون مقدار {fd.Title}");
                    }
                    return;
                }

                result.Write(_fieldFactoryProvider.GetFieldFactory(fd.Type).LoadField(field.RawValue, fd.Title, fd.MetaData)
                             .Veiw());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                result.Write("خطا");
            }
        }
Esempio n. 2
0
        private void CheckFieldValueValidation(Field field)
        {
            var factory = _customFieldFactoryProvider.GetFieldFactory(WorkingFieldDefention.Type);

            if (field.RawValue != null && !factory.IsValidForField(field.RawValue, WorkingFieldDefention.MetaData))
            {
                throw new InValidFieldValueException(field.FieldDefenition, factory.GetType());
            }
        }
Esempio n. 3
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,
                });
            }
        }
Esempio n. 4
0
        public static void CheckFieldDefenition(this FieldDefenition model, CustomFieldFactoryProvider <JObject> customFieldFactoryProvider)
        {
            var fieldFactory = customFieldFactoryProvider.GetFieldFactory(model.Type);

            if (fieldFactory == null)
            {
                throw new ArgumentNullException($"{nameof(fieldFactory)} => {model.Type}");
            }

            if (model.DefaultValue != null &&
                !fieldFactory.IsValidForField(model.DefaultValue, model.MetaData))
            {
                throw new InValidFieldValueException(model, fieldFactory.GetType());
            }
        }