示例#1
0
        public IEnumerable <FormDataApiModel> GetByForm(string formId, int top)
        {
            List <FormDataApiModel> output = new List <FormDataApiModel>();
            var formDatas = _formDataService.Get()
                            .Where(m => m.FormId == formId)
                            .OrderByDescending(m => m.ID)
                            .Take(top)
                            .ToList();

            foreach (var item in formDatas)
            {
                item.Datas = _formDataItemService.Get(m => m.FormDataId == item.ID).ToList();
                List <FormDataApiFieldValue> fieldValues = new List <FormDataApiFieldValue>();
                foreach (var dataItem in item.Datas.GroupBy(m => m.FieldId))
                {
                    string[] valueArray = dataItem.Select(m => m.FieldValue).ToArray();
                    FormDataApiFieldValue fieldValue = new FormDataApiFieldValue
                    {
                        FieldId         = dataItem.Key,
                        FieldName       = dataItem.First().FieldText,
                        FieldValueArray = valueArray,
                        FieldValue      = string.Join(',', valueArray)
                    };
                    fieldValues.Add(fieldValue);
                }
                output.Add(new FormDataApiModel
                {
                    ID          = item.ID,
                    FieldValues = fieldValues
                });
            }
            return(output);
        }
示例#2
0
        public override FormData Get(params object[] primaryKey)
        {
            var formData = base.Get(primaryKey);

            formData.Form  = _formService.Get(formData.FormId);
            formData.Datas = _formDataItemService.Get(m => m.FormDataId == formData.ID).ToList();
            MergeDataToForm(formData);
            return(formData);
        }
示例#3
0
        public override FormData Get(params object[] primaryKey)
        {
            var formData = base.Get(primaryKey);

            formData.Form  = _formService.Get(formData.FormId);
            formData.Datas = _formDataItemService.Get(m => m.FormDataId == formData.ID).ToList();
            if (formData.Form != null)
            {
                foreach (var item in formData.Form.FormFields)
                {
                    List <string> values = new List <string>();
                    foreach (var value in formData.Datas.Where(m => m.FieldId == item.ID))
                    {
                        if (value.OptionValue.IsNotNullAndWhiteSpace() && item.FieldOptions != null && item.FieldOptions.Any())
                        {
                            var option = item.FieldOptions.FirstOrDefault(o => o.Value == value.OptionValue);
                            if (option != null)
                            {
                                option.Selected = true;
                            }
                        }
                        else
                        {
                            values.Add(value.FieldValue);
                        }
                    }
                    if (values.Count == 1)
                    {
                        item.Value = values[0];
                    }
                    else if (values.Count > 1)
                    {
                        item.Value = JsonConvert.SerializeObject(values);
                    }
                }
            }
            return(formData);
        }