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); }
public string AddAsNewStandard() { ExtraValueName = ExtraValueName.Replace('/', '-'); var fields = Views.GetStandardExtraValues(DbUtil.Db, ExtraValueTable); var existing = fields.SingleOrDefault(ff => ff.Name == ExtraValueName); if (existing != null) { throw new Exception($"{ExtraValueName} already exists"); } TryCheckIntegrity(); var v = new CmsData.ExtraValue.Value { Type = ExtraValueType.Value, Name = ExtraValueName, VisibilityRoles = VisibilityRoles, Codes = ConvertToCodes(), Link = HttpUtility.HtmlEncode(ExtraValueLink) }; var i = Views.GetViewsView(DbUtil.Db, ExtraValueTable, ExtraValueLocation); i.view.Values.Add(v); i.views.Save(DbUtil.Db); return(null); }
public void Add(CMSDataContext db) { var fields = Views.GetStandardExtraValues(db, Table); const string defaultCodes = @" Option 1 Option 2 "; var codes = Type == "Bits" ? Checkboxes : Type == "Code" ? Codes ?? defaultCodes : null; var a = codes.SplitLines(noblanks: true).Select(ss => BitPrefix + ss).ToList(); var v = new Value { Type = Type, Name = Name, VisibilityRoles = VisibilityRoles, Codes = a, //Link = HttpUtility.HtmlEncode(ExtraValueLink) }; var i = Views.GetViewsView(db, Table, Location); i.view.Values.Add(v); i.views.Save(db); }
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}"); }
public void ConvertToStandard(string name) { // var oldfields = StandardExtraValues.GetExtraValues().ToList(); var oldfields = CmsData.ExtraValue.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(); //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; 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}"); }
public string AddAsNewStandard() { ExtraValueName = ExtraValueName.Replace('/', '-'); var fields = Views.GetStandardExtraValues(DbUtil.Db, ExtraValueTable); var existing = fields.SingleOrDefault(ff => ff.Name == ExtraValueName); if (existing != null) throw new Exception($"{ExtraValueName} already exists"); TryCheckIntegrity(); var v = new CmsData.ExtraValue.Value { Type = ExtraValueType.Value, Name = ExtraValueName, VisibilityRoles = VisibilityRoles, Codes = ConvertToCodes(), Link = HttpUtility.HtmlEncode(ExtraValueLink) }; var i = Views.GetViewsView(DbUtil.Db, ExtraValueTable, ExtraValueLocation); i.view.Values.Add(v); i.views.Save(DbUtil.Db); return null; }