Example #1
0
        private bool CreateExtraValueBits(string name, ExtraValue ev, CmsData.ExtraValue.Value v)
        {
            if (!name.Contains(":"))
            {
                return(false);
            }
            var prefix  = name.GetCsvToken(1, 2, ":");
            var allbits = (from vv in DbUtil.Db.PeopleExtras
                           where vv.Field.StartsWith($"{prefix}:")
                           orderby vv.Field
                           select vv.Field).Distinct().ToList();

            if (allbits.Count <= 1)
            {
                return(false);
            }
            v.Name  = prefix;
            v.Type  = "Bits";
            v.Codes = allbits;
            var view = Views.GetViewsView(DbUtil.Db, ExtraValueTable, ExtraValueLocation);

            view.view.Values.Add(v);
            view.views.Save(DbUtil.Db);
            DbUtil.LogActivity($"EV{ExtraValueTable} ConvertToStandard {name}");
            return(true);
        }
Example #2
0
        public override string ToString()
        {
            var ev = Extravalue;

            if (ev == null)
            {
                ev = new ExtraValue();
            }
            switch (Type)
            {
            case "Bit":
                if (Extravalue == null)
                {
                    if (!Standard)
                    {
                        return("Click to edit");
                    }
                    else
                    {
                        return("false");
                    }
                }
                return(ev.BitValue.ToString());

            case "Code":
                return(ev.StrValue);

            case "Text":
            case "Text2":
            case "Data":
                return((ev.Data ?? "").Trim());

            case "Attr":
                return("Attributes");

            case "Date":
                return(ev.DateValue.FormatDate());

            case "Bits":
            {
                var q = from e in Model.ListExtraValues()
                        where e.BitValue == true
                        where e.Id == Id
                        where Codes.Contains(e.Field)
                        select NoPrefix(e.Field);

                return(string.Join("\n", q));
            }

            case "Int":
                return(ev.IntValue.ToString2("d"));
            }
            return("");
        }
Example #3
0
        internal static Value AddField(Value f, ExtraValue ev, ExtraValueModel m = null)
        {
            if (f == null)
            {
                f = new Value
                {
                    Name = ev.Field,
                    Standard = false
                };
                f.Type = ev.Type;
            }
            else
                f.Standard = true;

            f.Id = ev?.Id ?? (m?.Id ?? 0);
            f.Extravalue = ev;
            f.Model = m;
            return f;
        }
Example #4
0
        internal static Value AddField(Value f, ExtraValue ev, ExtraValueModel m = null)
        {
            if (f == null)
            {
                f = new Value
                {
                    Name     = ev.Field,
                    Standard = false
                };
                f.Type = ev.Type;
            }
            else
            {
                f.Standard = true;
            }

            f.Id         = ev?.Id ?? (m?.Id ?? 0);
            f.Extravalue = ev;
            f.Model      = m;
            return(f);
        }
Example #5
0
        public void ConvertToStandard(string name)
        {
            //            var oldfields = StandardExtraValues.GetExtraValues().ToList();
            var           oldfields = Views.GetStandardExtraValues(DbUtil.Db, "People");
            ExtraValue    ev        = null;
            List <string> codes     = null;
            var           v         = new CmsData.ExtraValue.Value {
                Name = name
            };

            switch (ExtraValueTable)
            {
            case "People":
                ev = (from vv in DbUtil.Db.PeopleExtras
                      where vv.Field == name
                      select new ExtraValue(vv, null)).First();

                if (CreateExtraValueBits(name, ev, v))
                {
                    return;
                }

                //StandardExtraValues.Field bits = null;
                var bits = oldfields.SingleOrDefault(ff => ff.Codes.Contains(name));
                if (bits != null)
                {
                    codes             = bits.Codes;
                    ev.Type           = "Bits";
                    v.Name            = bits.Name;
                    v.VisibilityRoles = bits.VisibilityRoles;
                }
                else
                {
                    var f = oldfields.SingleOrDefault(ff => ff.Name == name);
                    if (f != null)
                    {
                        v.VisibilityRoles = f.VisibilityRoles;
                    }
                    if (ev.Type == "Code")
                    {
                        codes = (from vv in DbUtil.Db.PeopleExtras
                                 where vv.Field == name
                                 select vv.StrValue).Distinct().ToList();
                    }
                }
                break;

            case "Organization":
                ev = (from vv in DbUtil.Db.OrganizationExtras
                      where vv.Field == name
                      select new ExtraValue(vv, null)).First();
                if (ev.Type == "Code")
                {
                    codes = (from vv in DbUtil.Db.OrganizationExtras
                             where vv.Field == name
                             select vv.StrValue).Distinct().ToList();
                }
                break;

            case "Family":
                ev = (from vv in DbUtil.Db.FamilyExtras
                      where vv.Field == name
                      select new ExtraValue(vv, null)).First();
                if (ev.Type == "Code")
                {
                    codes = (from vv in DbUtil.Db.FamilyExtras
                             where vv.Field == name
                             select vv.StrValue).Distinct().ToList();
                }
                break;

            case "Meeting":
                ev = (from vv in DbUtil.Db.MeetingExtras
                      where vv.Field == name
                      select new ExtraValue(vv, null)).First();
                if (ev.Type == "Code")
                {
                    codes = (from vv in DbUtil.Db.MeetingExtras
                             where vv.Field == name
                             select vv.StrValue).Distinct().ToList();
                }
                break;

            case "OrgMember":
                ev = (from vv in DbUtil.Db.OrgMemberExtras
                      where vv.Field == name
                      select new ExtraValue(vv, null)).First();
                if (ev.Type == "Code")
                {
                    codes = (from vv in DbUtil.Db.OrgMemberExtras
                             where vv.Field == name
                             select vv.StrValue).Distinct().ToList();
                }
                break;

            default:
                return;
            }
            v.Type  = ev.Type;
            v.Codes = codes;
            var i = Views.GetViewsView(DbUtil.Db, ExtraValueTable, ExtraValueLocation);

            i.view.Values.Add(v);
            i.views.Save(DbUtil.Db);
            DbUtil.LogActivity($"EV{ExtraValueTable} ConvertToStandard {name}");
        }
Example #6
0
 public override string ToString()
 {
     var ev = Extravalue;
     if (ev == null)
         ev = new ExtraValue();
     switch (Type)
     {
         case "Bit":
             if (Extravalue == null)
                 if (!Standard)
                     return "Click to edit";
                 else return "false";
             return ev.BitValue.ToString();
         case "Code":
             return ev.StrValue;
         case "Text":
         case "Text2":
         case "Data":
             return (ev.Data ?? "").Trim();
         case "Date":
             return ev.DateValue.FormatDate();
         case "Bits":
         {
             var q = from e in Model.ListExtraValues()
                     where e.BitValue == true
                     where e.Id == Id
                     where Codes.Contains(e.Field)
                     select e.Field;
             return string.Join("<br/>\n", q);
         }
         case "Int":
             return ev.IntValue.ToString2("d");
     }
     return "";
 }
Example #7
0
        public override string ToString()
        {
            var ev = Extravalue;

            if (ev == null)
            {
                ev = new ExtraValue();
            }
            switch (Type)
            {
            case "Bit":
                if (Extravalue == null)
                {
                    if (!Standard)
                    {
                        return("Click to edit");
                    }
                    else
                    {
                        return("false");
                    }
                }
                return(ev.BitValue.ToString());

            case "Code":
                return(ev.StrValue);

            case "Text":
            case "Text2":
            case "Data":
                return((ev.Data ?? "").Trim());

            case "Attr":
                return("Attributes");

            case "Date":
                return(ev.DateValue.FormatDate());

            case "Bits":
            {
                var q = (from e in Model.ListExtraValues()
                         where e.BitValue == true
                         where e.Id == Id
                         where Codes.Select(x => x.Text).Contains(e.Field)
                         select NoPrefix(e.Field)).ToList();

                if (DbUtil.Db.Setting("UX-RenderCheckboxBullets"))
                {
                    if (q.ToList().Count == 0)
                    {
                        return(string.Empty);
                    }

                    var bullets = string.Join("</span></li><li><span>", q);
                    return("<ul class=\"extra-value-list\"><li><span>" + bullets + "</span></li></ul>");
                }

                return(string.Join("<br/>", q));
            }

            case "Int":
                return(ev.IntValue.ToString2("d"));
            }
            return("");
        }
 private bool CreateExtraValueBits(string name, ExtraValue ev, CmsData.ExtraValue.Value v)
 {
     if (!name.Contains(":"))
         return false;
     var prefix = name.GetCsvToken(1, 2, ":");
     var allbits = (from vv in DbUtil.Db.PeopleExtras
                    where vv.Field.StartsWith($"{prefix}:")
                    orderby vv.Field
                    select vv.Field).Distinct().ToList();
     if (allbits.Count <= 1)
         return false;
     v.Name = prefix;
     v.Type = "Bits";
     v.Codes = allbits;
     var view = Views.GetViewsView(DbUtil.Db, ExtraValueTable, ExtraValueLocation);
     view.view.Values.Add(v);
     view.views.Save(DbUtil.Db);
     DbUtil.LogActivity($"EV{ExtraValueTable} ConvertToStandard {name}");
     return true;
 }