Exemplo n.º 1
0
 private static IEnumerable<ModelClientValidationRule> GetRulesFromAttributes(PropertyVm property)
 {
     return property.GetCustomAttributes()
                    .SelectMany(attribute => UnobtrusiveValidationAttributeRules,
                                (attribute, rule) => rule(property, attribute))
                    .Where(r => r != null);
 }
Exemplo n.º 2
0
        public DateTimeOffsetVm(PropertyVm model)
        {
            var dateAttr = model
                           .GetCustomAttributes()
                           .FirstOrDefault(a => a is DateAttribute || a is DateTimeAttribute);
            var isDate = dateAttr is DateAttribute;
            var displayFormatAttribute = model.GetCustomAttributes().OfType <DisplayFormatAttribute>().SingleOrDefault();

            stringFormat = (displayFormatAttribute != null ? displayFormatAttribute.DataFormatString : null) ??
                           (isDate ? "dd MMM yyyy" : "g");
            behaviour = isDate ? "datepicker" : "datetimepicker";
            if (model.Value is string)
            {
                valueAsString = model.Value as string;
            }
            else
            {
                var dateTimeOffset = model.Value as DateTimeOffset?;
                if (dateTimeOffset == null)
                {
                    valueAsString = "";
                }
                else
                {
                    valueAsString = ((DateTimeOffset?)model.Value).Value.ToString(stringFormat);
                }
            }
        }
Exemplo n.º 3
0
 private static ModelClientValidationRule RequiredAttributeRule(PropertyVm propertyVm, object attribute)
 {
     var a = attribute as RequiredAttribute;
     return (a == null)
                ? null
                : new ModelClientValidationRequiredRule(a.FormatErrorMessage(propertyVm.DisplayName));
 }
Exemplo n.º 4
0
        private static FormVm BuildFormVmFromAction(SirenDotNet.Action action)
        {
            var form = new FormVm
            {
                ActionUrl   = action.Href.ToString(),
                DisplayName = action.Title ?? action.Name ?? "link",
                Method      = action?.Method.ToString().ToLower(),
                Inputs      = action.Fields?.Select(field =>
                {
                    var propertyVm = new PropertyVm(typeof(string), field.Name)
                    {
                        DisplayName = field.Name
                    };
                    if (field.Type.ToString() == "select")
                    {
                        propertyVm.Choices = ((IEnumerable <JObject>)field.ExtensionData["options"])
                                             .Select(jo => Tuple.Create(jo["name"].Value <string>(), jo["value"].Value <string>()));
                    }
                    return(propertyVm);
                })?.ToArray() ?? Enumerable.Empty <PropertyVm>().ToArray()
            };



            if (form.Method != "get" && form.Method != "post")
            {
                form.ActionUrl += form.ActionUrl.Contains("?") ? "&" : "?";
                form.ActionUrl += "_method=" + form.Method.ToString().ToUpper();
                form.Method     = "post";
            }
            return(form);
        }
        public static PropertyVm ToPropertyVm(this IInvokeableParameter parameter)
        {
            var customAtts = new List<object>();
            var querySuggestionsNodeMethod = parameter.QuerySuggestions()
                                             ?? parameter.QueryChoices();
            if (querySuggestionsNodeMethod != null)
            {
                customAtts.Add(new SuggestionsUrlAttribute(querySuggestionsNodeMethod.Url.ToString()));
            }

            var vm = new PropertyVm(parameter.ValueType, parameter.Name);

            {
                vm.DisplayName = parameter.DisplayName;
                vm.GetCustomAttributes = () => parameter.Attributes.Concat(customAtts);
                vm.Readonly = parameter.Readonly;
                vm.IsHidden = parameter.Attributes.OfType<DataTypeAttribute>().Any(x => x.CustomDataType == "Hidden");
                vm.Value = parameter.Value;
                vm.NotOptional = (parameter.Choices != null || parameter.QueryChoices() != null) ? true : null as bool?;
                vm.Choices = parameter.Choices;
                vm.Suggestions = parameter.Suggestions;
                vm.Source = parameter;
            };
            return vm;
        }
Exemplo n.º 6
0
 public DateTimeOffsetVm(PropertyVm model)
 {
     var dateAttr = model.GetCustomAttributes()
                         .OfType<DataTypeAttribute>()
                         .FirstOrDefault(dt => dt.DataType == DataType.Date || dt.DataType == DataType.DateTime)
                    ?? new DataTypeAttribute(DataType.DateTime);
     var isDate = dateAttr.DataType == DataType.Date;
     var displayFormatAttribute = model.GetCustomAttributes().OfType<DisplayFormatAttribute>().SingleOrDefault();
     stringFormat = (displayFormatAttribute != null ? displayFormatAttribute.DataFormatString : null) ??
                        (isDate ? "dd MMM yyyy" : "g");
     behaviour = isDate ? "datepicker" : "datetimepicker";
     if (model.Value is string) valueAsString = model.Value as string;
     else
     {
         var dateTimeOffset = model.Value as DateTimeOffset?;
         if (dateTimeOffset == null)
         {
             valueAsString = "";
         }
         else
         {
             valueAsString = ((DateTimeOffset?) model.Value).Value.ToString(stringFormat);
         }
     }
 }
Exemplo n.º 7
0
 private static ModelClientValidationRule RegexAttributeRule(PropertyVm propertyVm, object attribute)
 {
     var a = attribute as RegularExpressionAttribute;
     return (a == null)
                ? null
                : new ModelClientValidationRegexRule(a.FormatErrorMessage(propertyVm.DisplayName), a.Pattern);
 }
Exemplo n.º 8
0
        internal static PropertyVm AreaCaption(this MeasureBoundary <int, Area> livingSpace)
        {
            PropertyVm propertyVm = new PropertyVm();

            if (livingSpace != null && (livingSpace.Min.HasValue || livingSpace.Max.HasValue))
            {
                propertyVm.Unit = livingSpace.Measure.GetEnumLocalizedValue <Area>();
                if (!livingSpace.Min.HasValue || !livingSpace.Max.HasValue || livingSpace.Min.Value == livingSpace.Max.Value || livingSpace.Min.Value == 0 || livingSpace.Max.Value == 0)
                {
                    decimal num = (livingSpace.Min.HasValue ? livingSpace.Min.Value : livingSpace.Max.Value);
                    if (num != decimal.Zero)
                    {
                        decimal num1 = Math.Round(num);
                        propertyVm.Value = string.Format("{0}", num1.ToString(ConfigurationManager.Instance.NumberFormat));
                    }
                }
                else
                {
                    int    value = livingSpace.Min.Value;
                    string str   = value.ToString(ConfigurationManager.Instance.NumberFormat);
                    value            = livingSpace.Max.Value;
                    propertyVm.Value = string.Format("{0} - {1}", str, value.ToString(ConfigurationManager.Instance.NumberFormat));
                }
            }
            return(propertyVm);
        }
Exemplo n.º 9
0
 public static string GetInputTypeFromDataTypeAttribute(PropertyVm Model)
 {
     var dataAttributes = Model.GetCustomAttributes().OfType<DataTypeAttribute>().ToList();
     var inputType = "text";
     if (dataAttributes.Any(da => da.DataType == DataType.Password)) inputType = "password";
     if (dataAttributes.Any(da => da.DataType == DataType.MultilineText)) inputType = "textarea";
     return inputType;
 }
Exemplo n.º 10
0
 private static ModelClientValidationRule StringLengthAttributeRule(PropertyVm propertyVm, object attribute)
 {
     var a = attribute as StringLengthAttribute;
     return (a == null)
                ? null
                : new ModelClientValidationStringLengthRule(a.FormatErrorMessage(propertyVm.DisplayName),
                                                            a.MinimumLength, a.MaximumLength);
 }
Exemplo n.º 11
0
 private static ModelClientValidationRule RangeAttribteRule(PropertyVm propertyVm, object attribute)
 {
     var a = attribute as RangeAttribute;
     return (a == null)
                ? null
                : new ModelClientValidationRangeRule(a.FormatErrorMessage(propertyVm.DisplayName), a.Minimum,
                                                     a.Maximum);
 }
Exemplo n.º 12
0
        public static async Task <string> RenderAsync(this PropertyVm propertyVm)
        {
            using (var serviceScope = RazorContextBuilder.ServiceScopeFactory.Value.CreateScope())
            {
                var helper = serviceScope.ServiceProvider.GetRequiredService <RazorViewToStringRenderer>();

                return(await helper.RenderViewToStringAsync("Views/Shared/FormFactory/Form.Property.cshtml",
                                                            propertyVm));
            }
        }
Exemplo n.º 13
0
 public static void PropertyDescription(PropertyVm item, bool flag, Action <bool> flagSetter)
 {
     if (!flag)
     {
         item.Clear();
     }
     else if (!item.IsValued)
     {
         flagSetter(obj: false);
     }
 }
        private static PropertyVm PropertyVmFromJToken(JProperty property)
        {
            var propertyVm = new PropertyVm(typeof(string), property.Name)
            {
                Value       = property.Value.ToString(),
                Readonly    = true,
                DisplayName = property.Name,
            };

            //propertyVm.GetCustomAttributes = () => new object[] {new DataTypeAttribute(DataType.MultilineText)};
            return(propertyVm);
        }
Exemplo n.º 15
0
 public static string GetTypeAheadAttribute(PropertyVm model)
 {
     if (model.Suggestions != null)
     {
         var suggestions = model.Suggestions.Cast <string>().ToArray();
         if (suggestions.Any())
         {
             var escapedSuggestions = suggestions.Select(s => "\"" + s.Replace("\"", "\"\"") + "\"");
             return(" data-provide=\"typeahead\" data-source='[" + string.Join(",", escapedSuggestions) + "]' autocomplete=\"off\"");
         }
     }
     return("");
 }
Exemplo n.º 16
0
 public static string GetTypeAheadAttribute(PropertyVm model)
 {
     if (model.Suggestions != null)
     {
         var suggestions = model.Suggestions.Cast<string>().ToArray();
         if (suggestions.Any())
         {
             var escapedSuggestions = suggestions.Select(s => "\"" + s.Replace("\"", "\"\"") + "\"");
             return (" data-provide=\"typeahead\" data-source='[" + string.Join(",", escapedSuggestions) + "]' autocomplete=\"off\"");
         }
     }
     return ("");
 }
Exemplo n.º 17
0
        public ObjectChoices[] Choices(PropertyVm model) //why is this needed? HM
        {
            var html    = this;
            var choices = (from obj in model.Choices.Cast <object>().ToArray()
                           let choiceType = obj == null ? model.Type : obj.GetType()
                                            let properties = FF.PropertiesFor(obj, choiceType)
                                                             .Each(p => p.Name = model.Name + "." + p.Name)
                                                             .Each(p => p.Readonly |= model.Readonly)
                                                             .Each(p => p.Id = Guid.NewGuid().ToString())
                                                             select new ObjectChoices {
                obj = obj, choiceType = choiceType, properties = properties, name = (obj != null ? obj.DisplayName() : choiceType.DisplayName())
            }).ToArray();

            return(choices);
        }
Exemplo n.º 18
0
        public static string GetInputTypeFromDataTypeAttribute(PropertyVm Model)
        {
            var dataAttributes = Model.GetCustomAttributes().OfType <DataTypeAttribute>().ToList();
            var inputType      = "text";

            if (dataAttributes.Any(da => da.DataType == DataType.Password))
            {
                inputType = "password";
            }
            if (dataAttributes.Any(da => da.DataType == DataType.MultilineText))
            {
                inputType = "textarea";
            }
            return(inputType);
        }
Exemplo n.º 19
0
        public static string GetInputTypeFromDataTypeAttribute(PropertyVm Model)
        {
            var dataAttributes = Model.GetCustomAttributes().ToArray();
            var inputType      = "text";

            if (dataAttributes.OfType <PasswordAttribute>().Any())
            {
                inputType = "password";
            }
            if (dataAttributes.OfType <MultilineTextAttribute>().Any())
            {
                inputType = "textarea";
            }
            return(inputType);
        }
 public RawString BestProperty(PropertyVm vm)
 {
     try
     {
         var viewname = ViewFinderExtensions.BestViewName(this.ViewFinder, vm.Type, "FormFactory/Property.");
         viewname = viewname ??
                    ViewFinderExtensions.BestViewName(ViewFinder, vm.Type.GetEnumerableType(), "FormFactory/Property.IEnumerable.");
         viewname = viewname ?? "FormFactory/Property.System.Object";
         //must be some unknown object exposed as an interface
         return(Partial(viewname, vm));
     }
     catch (Exception ex)
     {
         return(new RawString(ex.Message));
     }
 }
        private static PropertyVm BuildPropertyVmFromLink(Link link)
        {
            var element = new XElement("a", new XAttribute("href", link.Href));

            var rels = string.Join(", ", link.Rel);

            element.SetAttributeValue("title", rels);
            element.Value = link.Title ?? rels;
            var propertyVm = new PropertyVm(typeof(XElement), rels)
            {
                Value               = element,
                Readonly            = true,
                DisplayName         = rels,
                Name                = rels,
                GetCustomAttributes = () => new object[] { new NoLabelAttribute() }
            };

            return(propertyVm);
        }
Exemplo n.º 22
0
        public static IEnumerable<PropertyVm> GetPropertyVmsUsingReflection(IStringEncoder helper, object model, Type fallbackModelType)
        {
            var type = model != null ? model.GetType() : fallbackModelType;

            var typeVm = new PropertyVm(typeof(string), "__type")
                {
                    DisplayName = "",
                    IsHidden = true,
                    Value = helper.WriteTypeToString(type)
                };

            yield return typeVm;
            var properties = type.GetProperties();

            foreach (var property in properties)
            {
                if (properties.Any(p => p.Name + "Choices" == property.Name))
                {
                    continue; //skip this is it is choice
                }

                var inputVm = new PropertyVm(model, property);
                PropertyInfo choices = properties.SingleOrDefault(p => p.Name == property.Name + "_choices");
                if (choices != null)
                {
                    inputVm.Choices = (IEnumerable)choices.GetGetMethod().Invoke(model, null);
                }
                PropertyInfo suggestions = properties.SingleOrDefault(p => p.Name == property.Name + "_suggestions");
                if (suggestions != null)
                {
                    inputVm.Suggestions = (IEnumerable)suggestions.GetGetMethod().Invoke(model, null);
                }

                yield return inputVm;
            }
        }
Exemplo n.º 23
0
 public static string[] EscapedSuggestions(PropertyVm model)
 {
     return model.Suggestions.Cast<string>().Select(s => s.Replace("'", "''")).ToArray();
 }
Exemplo n.º 24
0
 public static RawString Render(this PropertyVm propertyVm, RazorTemplateHtmlHelper html)
 {
     return(html.Partial("FormFactory/Form.Property", propertyVm));
 }
Exemplo n.º 25
0
 public static IHtmlContent Readonly(this PropertyVm vm)
 {
     return(Attr(vm.Readonly, "readonly", null));
 }
Exemplo n.º 26
0
 public static IHtmlContent InputAtts(this PropertyVm vm)
 {
     return(new HtmlString(string.Join("", string.Join(" ", new string[] { vm.Disabled().ToString(), vm.Readonly().ToString(), vm.DataAtts().ToString() }))));
 }
Exemplo n.º 27
0
 public static RawString Readonly(this PropertyVm vm)
 {
     return(Attr(vm.Readonly, "readonly", null));
 }
Exemplo n.º 28
0
 public static bool UseRadio(PropertyVm vm)
 {
     return(vm.GetCustomAttributes().OfType <RadioAttribute>().Any());
 }
Exemplo n.º 29
0
 public static bool UseRadio(PropertyVm vm)
 {
     return vm.GetCustomAttributes().OfType<DataTypeAttribute>().Any(dt => dt.CustomDataType == "Radio");
 }
 public static System.Web.IHtmlString BestProperty(this HtmlHelper html, PropertyVm vm)
 {
     string viewName = ViewFinderExtensions.BestPropertyName(new FormFactoryHtmlHelper(html), vm);
     return html.Partial(viewName, vm);
 }
        /// <summary>
        /// Get all Records for a project
        /// </summary>
        /// <param name="id">ProjectId</param>
        /// <returns></returns>
        public async Task <IActionResult> RecordsPerProject(Guid id, bool withOnlyGeometries = false)
        {
            User user = Helpers.UserHelper.GetCurrentUser(User, db);

            List <Project> projects           = new List <Project>();
            List <Project> erfassendeProjects = new List <Project>();

            if (User.IsInRole("DM"))
            {
                projects = await DB.Helpers.ProjectManager.UserProjectsAsync(db, user, RoleEnum.DM);
            }

            if (User.IsInRole("EF"))
            {
                erfassendeProjects = await DB.Helpers.ProjectManager.UserProjectsAsync(db, user, RoleEnum.EF);
            }
            if (User.IsInRole("PK"))
            {
                projects.AddRange(await DB.Helpers.ProjectManager.UserProjectsAsync(db, user, RoleEnum.PK));
            }
            if (User.IsInRole("PL"))
            {
                projects.AddRange(await DB.Helpers.ProjectManager.UserProjectsAsync(db, user, RoleEnum.PL));
            }

            projects.AddRange(await DB.Helpers.ProjectManager.UserProjectsAsync(db, user, RoleEnum.LE));
            projects.AddRange(erfassendeProjects);

            Project p = await db.Projects
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.TextData).ThenInclude(td => td.FormField)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.NumericData).ThenInclude(td => td.FormField)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.BooleanData).ThenInclude(td => td.FormField)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.Form).ThenInclude(f => f.FormFormFields).ThenInclude(fff => fff.FormField)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.Form).ThenInclude(f => f.FormFormFields).ThenInclude(fff => fff.FormField).ThenInclude(mo => mo.PublicMotherFormField)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.ProjectGroup.Group)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.Geometry)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).ThenInclude(u => u.RecordChangeLogs).ThenInclude(rcl => rcl.ChangeLog).ThenInclude(cl => cl.User)
                        .Include(m => m.ProjectGroups).ThenInclude(pg => pg.Records).Where(pg => pg.StatusId != StatusEnum.deleted)
                        .Where(m => m.ProjectId == id)
                        .Where(m => m.StatusId != StatusEnum.deleted).FirstOrDefaultAsync();

            if (p == null)
            {
                return(StatusCode(500));
            }
            if (!projects.Any(m => m.ProjectId == p.ProjectId))
            {
                return(RedirectToAction("NotAllowed", "Home"));
            }

            ProjectViewModel pvm = new ProjectViewModel()
            {
                Project = p
            };

            pvm.Records = new List <RecordViewModel>();

            List <Group> myGroups = await db.Groups.Where(m => m.GroupUsers.Any(u => u.UserId == user.UserId)).ToListAsync();

            foreach (ProjectGroup g in p.ProjectGroups)
            {
                List <Record> records = g.Records.Where(m => m.StatusId != StatusEnum.deleted && m.Geometry == null).ToList();
                if (withOnlyGeometries)
                {
                    records = g.Records.Where(m => m.StatusId != StatusEnum.deleted && m.Geometry != null).ToList();
                }

                foreach (Record r in records)
                {
                    bool isReadOnly = true;
                    if ((g.GroupStatusId != GroupStatusEnum.Gruppendaten_gueltig) && (g.GroupStatusId != GroupStatusEnum.Gruppendaten_erfasst))
                    {
                        if (myGroups.Where(m => m.GroupId == g.GroupId).Count() > 0)
                        {
                            isReadOnly = false;
                        }
                    }

                    RecordViewModel rvm = new RecordViewModel()
                    {
                        Record = r
                    };

                    List <PropertyVm> dynamicForm = new List <PropertyVm>();

                    // BDC Guid
                    PropertyVm dynamicFieldGUID = new PropertyVm(typeof(string), "Field_" + r.RecordId);
                    dynamicFieldGUID.DisplayName         = "BDCGuid";
                    dynamicFieldGUID.Value               = r.BDCGuid;
                    dynamicFieldGUID.GetCustomAttributes = () => new object[] { new Helpers.FormFactory.GuidAttribute() };
                    dynamicForm.Add(dynamicFieldGUID);

                    if (r.Form != null)
                    {
                        foreach (FormField ff in r.Form.FormFormFields.Select(fff => fff.FormField).OrderBy(m => m.Order))
                        {
                            FormField origFormField = ff;
                            if (ff.PublicMotherFormField != null)
                            {
                                origFormField = ff.PublicMotherFormField;
                            }

                            if (origFormField.FieldTypeId == FieldTypeEnum.Text)
                            {
                                PropertyVm dynamicField = new PropertyVm(typeof(string), "Field_" + ff.FormFieldId.ToString());
                                dynamicField.DisplayName = origFormField.Title;
                                TextData td = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                                if (td != null)
                                {
                                    dynamicField.Value = td.Value;
                                }

                                dynamicField.NotOptional = ff.Mandatory;
                                dynamicForm.Add(dynamicField);
                            }
                            else if (origFormField.FieldTypeId == FieldTypeEnum.DateTime)
                            {
                                PropertyVm dynamicField = new PropertyVm(typeof(DateTime), "Field_" + ff.FormFieldId.ToString());
                                dynamicField.DisplayName = origFormField.Title;
                                TextData td   = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                                DateTime myDT = new DateTime();
                                try
                                {
                                    myDT = DateTime.ParseExact(td.Value.Replace("{0:", " ").Replace("}", ""), formats, CultureInfo.InvariantCulture, DateTimeStyles.None);
                                }
                                catch (Exception e)
                                {
                                }

                                if (td != null)
                                {
                                    dynamicField.Value = myDT;
                                }

                                dynamicField.NotOptional = ff.Mandatory;
                                dynamicForm.Add(dynamicField);
                            }
                            else if (origFormField.FieldTypeId == FieldTypeEnum.Choice)
                            {
                                PropertyVm dynamicField = new PropertyVm(typeof(string), "Field_" + ff.FormFieldId.ToString());
                                dynamicField.DisplayName = origFormField.Title;
                                TextData td = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                                if (td != null)
                                {
                                    dynamicField.Value = td.Value;
                                }
                                await db.Entry(origFormField).Collection(m => m.FieldChoices).LoadAsync();

                                if (origFormField.FieldChoices != null)
                                {
                                    List <string> choices = new List <string>();
                                    foreach (FieldChoice fc in origFormField.FieldChoices.OrderBy(m => m.Order))
                                    {
                                        choices.Add(fc.Text);
                                    }
                                    dynamicField.Choices = choices;
                                }
                                dynamicField.NotOptional = ff.Mandatory;
                                dynamicForm.Add(dynamicField);
                            }
                            else if (origFormField.FieldTypeId == FieldTypeEnum.Boolean)
                            {
                                PropertyVm dynamicField = new PropertyVm(typeof(bool), "Field_" + ff.FormFieldId.ToString());
                                dynamicField.DisplayName = origFormField.Title;
                                BooleanData bd = r.BooleanData.Where(m => m.FormField == origFormField).FirstOrDefault();
                                if (bd != null)
                                {
                                    dynamicField.Value = bd.Value;
                                }
                                dynamicField.NotOptional         = ff.Mandatory;
                                dynamicField.GetCustomAttributes = () => new object[] { new FormFactory.Attributes.LabelOnRightAttribute() };
                                dynamicForm.Add(dynamicField);
                            }
                        }

                        PropertyVm dynamicHiddenField = new PropertyVm(typeof(string), "RecordId");
                        dynamicHiddenField.Value       = r.RecordId.ToString();
                        dynamicHiddenField.NotOptional = true;
                        dynamicHiddenField.IsHidden    = true;
                        dynamicForm.Add(dynamicHiddenField);

                        if (isReadOnly)
                        {
                            foreach (PropertyVm pv in dynamicForm)
                            {
                                pv.Readonly = true;
                            }
                        }
                        rvm.Readonly    = isReadOnly;
                        rvm.DynamicForm = dynamicForm;
                        rvm.Group       = r.ProjectGroup.Group;
                        pvm.Records.Add(rvm);
                    }
                }
            }
            ViewData["withOnlyGeometries"] = withOnlyGeometries;
            if (!erfassendeProjects.Contains(p))
            {
                ViewData["ReadOnly"] = true;
            }
            else
            {
                ViewData["ReadOnly"] = false;
            }
            if (withOnlyGeometries)
            {
                return(View("RecordsPerProjectPerGeometry", pvm));
            }
            return(View(pvm));
        }
Exemplo n.º 32
0
 public static IHtmlContent Disabled(this PropertyVm vm)
 {
     return(Attr(vm.Disabled, "disabled", null));
 }
Exemplo n.º 33
0
 public static RawString Disabled(this PropertyVm vm)
 {
     return(Attr(vm.Disabled, "disabled", null));
 }
Exemplo n.º 34
0
        public static IHtmlContent Placeholder(PropertyVm pi)
        {
            var placeHolderText = pi.GetCustomAttributes().OfType <DisplayAttribute>().Select(a => a.Prompt).FirstOrDefault();

            return(Attr((!string.IsNullOrWhiteSpace(placeHolderText)), "placeholder", placeHolderText));
        }
Exemplo n.º 35
0
        public static MvcHtmlString UnobtrusiveValidation(this HtmlHelper helper, PropertyVm property)
        {
            var unobtrusiveValidation = ValidationHelper.UnobtrusiveValidation(new FormFactoryHtmlHelper(helper), property);

            return new MvcHtmlString(unobtrusiveValidation);
        }
Exemplo n.º 36
0
 public static string[] EscapedSuggestions(PropertyVm model)
 {
     return(model.Suggestions.Cast <string>().Select(s => s.Replace("'", "''")).ToArray());
 }
Exemplo n.º 37
0
        public static RawString Placeholder(PropertyVm pi)
        {
            var placeHolderText = pi.GetCustomAttributes().OfType <PlaceholderAttribute>().Select(a => a.Text).FirstOrDefault();

            return(Attr((!string.IsNullOrWhiteSpace(placeHolderText)), "placeholder", placeHolderText));
        }
Exemplo n.º 38
0
 public static bool UseRadio(PropertyVm vm)
 {
     return(vm.GetCustomAttributes().OfType <DataTypeAttribute>().Any(dt => dt.CustomDataType == "Radio"));
 }
Exemplo n.º 39
0
        public static string UnobtrusiveValidation(FfHtmlHelper helper, PropertyVm property)
        {
            var sb = new StringBuilder();

            var rules = UnobtrusiveValidationRules.SelectMany(r => r(property));

            if (rules.Any() == false) return ("");

            sb.Append("data-val=\"true\" ");
            foreach (var rule in rules)
            {
                var prefix = string.Format(" data-val-{0}", rule.ValidationType);
                sb.AppendFormat(prefix + "=\"{0}\" ", rule.ErrorMessage);
                foreach (var parameter in rule.ValidationParameters)
                {
                    sb.AppendFormat(prefix + "-{0}=\"{1}\" ", parameter.Key, parameter.Value);
                }
            }

            return (sb.ToString());
        }
Exemplo n.º 40
0
 public static IHtmlContent Render(this PropertyVm propertyVm, IHtmlHelper html)
 {
     return(html.Partial("FormFactory/Form.Property", propertyVm));
 }
        public static async Task CreateDynamicView(BioDivContext db, ReferenceGeometry rg, ProjectGroup g, List <Group> myGroups, GeometrieViewModel gvm)
        {
            foreach (Record r in rg.Records.Where(m => m.StatusId != StatusEnum.deleted))
            {
                bool isReadOnly = true;
                if (g == null)
                {
                    isReadOnly = false;
                }
                else if ((g.GroupStatusId != GroupStatusEnum.Gruppendaten_gueltig) && (g.GroupStatusId != GroupStatusEnum.Gruppendaten_erfasst))
                {
                    if (myGroups.Where(m => m.GroupId == r.ProjectGroupGroupId).Count() > 0)
                    {
                        isReadOnly = false;
                    }
                }

                RecordViewModel rvm = new RecordViewModel()
                {
                    Record = r
                };

                List <PropertyVm> dynamicForm = new List <PropertyVm>();

                // BDC Guid
                PropertyVm dynamicFieldGUID = new PropertyVm(typeof(string), "Field_" + r.RecordId);
                dynamicFieldGUID.DisplayName         = "BDCGuid";
                dynamicFieldGUID.Value               = r.BDCGuid;
                dynamicFieldGUID.GetCustomAttributes = () => new object[] { new Helpers.FormFactory.GuidAttribute() };
                dynamicForm.Add(dynamicFieldGUID);

                if (r.Form != null)
                {
                    foreach (FormField ff in r.Form.FormFormFields.Select(fff => fff.FormField).OrderBy(m => m.Order))
                    {
                        FormField origFormField = ff;
                        if (ff.PublicMotherFormField != null)
                        {
                            origFormField = ff.PublicMotherFormField;
                        }

                        if (origFormField.FieldTypeId == FieldTypeEnum.Text)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(string), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            TextData td = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                            if (td != null)
                            {
                                dynamicField.Value = td.Value;
                            }

                            dynamicField.NotOptional = ff.Mandatory;
                            dynamicForm.Add(dynamicField);
                        }
                        else if (origFormField.FieldTypeId == FieldTypeEnum.DateTime)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(DateTime), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            TextData td   = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                            DateTime myDT = new DateTime();
                            try
                            {
                                myDT = DateTime.ParseExact(td.Value.Replace("{0:", " ").Replace("}", ""), formats, CultureInfo.InvariantCulture, DateTimeStyles.None);
                            }
                            catch (Exception e)
                            {
                            }

                            if (td != null)
                            {
                                dynamicField.Value = myDT;
                            }

                            dynamicField.NotOptional = ff.Mandatory;
                            dynamicForm.Add(dynamicField);
                        }
                        else if (origFormField.FieldTypeId == FieldTypeEnum.Choice)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(string), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            TextData td = r.TextData.Where(m => m.FormField == ff).FirstOrDefault();
                            if (td != null)
                            {
                                dynamicField.Value = td.Value;
                            }

                            await db.Entry(origFormField).Collection(m => m.FieldChoices).LoadAsync();

                            if (origFormField.FieldChoices != null)
                            {
                                List <string> choices = new List <string>();
                                foreach (FieldChoice fc in origFormField.FieldChoices.OrderBy(m => m.Order))
                                {
                                    choices.Add(fc.Text);
                                }
                                dynamicField.Choices = choices;
                            }
                            dynamicField.NotOptional = ff.Mandatory;
                            dynamicForm.Add(dynamicField);
                        }
                        else if (origFormField.FieldTypeId == FieldTypeEnum.Boolean)
                        {
                            PropertyVm dynamicField = new PropertyVm(typeof(bool), "Field_" + ff.FormFieldId.ToString());
                            dynamicField.DisplayName = origFormField.Title;
                            BooleanData bd = r.BooleanData.Where(m => m.FormField == ff).FirstOrDefault();
                            if (bd != null)
                            {
                                dynamicField.Value = bd.Value;
                            }
                            dynamicField.NotOptional         = ff.Mandatory;
                            dynamicField.GetCustomAttributes = () => new object[] { new FormFactory.Attributes.LabelOnRightAttribute() };
                            dynamicForm.Add(dynamicField);
                        }
                    }

                    PropertyVm dynamicHiddenField = new PropertyVm(typeof(string), "RecordId");
                    dynamicHiddenField.Value       = r.RecordId.ToString();
                    dynamicHiddenField.NotOptional = true;
                    dynamicHiddenField.IsHidden    = true;
                    dynamicForm.Add(dynamicHiddenField);

                    if (isReadOnly)
                    {
                        foreach (PropertyVm pv in dynamicForm)
                        {
                            pv.Readonly = true;
                        }
                    }
                    rvm.Readonly    = isReadOnly;
                    rvm.DynamicForm = dynamicForm;
                    rvm.Group       = r.ProjectGroup.Group;
                    gvm.Records.Add(rvm);
                }
            }

            return;
        }
 public RawString UnobtrusiveValidation(PropertyVm property)
 {
     return(new RawString(ValidationHelper.UnobtrusiveValidation(this, property)));
 }
Exemplo n.º 43
0
 public static IHtmlString Placeholder(PropertyVm pi)
 {
     var placeHolderText = pi.GetCustomAttributes().OfType<PlaceholderAttribute>().Select(a => a.Text).FirstOrDefault();
     return Attr((!string.IsNullOrWhiteSpace(placeHolderText)), "placeholder", placeHolderText);
 }