public TranslatedInstanceViewTypeTS View(string type, string?culture, string filter) { Type t = TypeLogic.GetType(type); var c = culture == null ? null : CultureInfo.GetCultureInfo(culture); var master = TranslatedInstanceLogic.FromEntities(t); var support = TranslatedInstanceLogic.TranslationsForType(t, culture: c); var all = string.IsNullOrEmpty(filter); var cultures = TranslationLogic.CurrentCultureInfos(TranslatedInstanceLogic.DefaultCulture); Func <LocalizedInstanceKey, bool> filtered = li => all || li.RowId.ToString() == filter || li.Instance.Id.ToString() == filter || li.Route.PropertyString().Contains(filter, StringComparison.InvariantCultureIgnoreCase) || master.GetOrThrow(li).Contains(filter, StringComparison.InvariantCultureIgnoreCase) || cultures.Any(ci => (support.TryGetC(ci)?.TryGetC(li)?.TranslatedText ?? "").Contains(filter, StringComparison.InvariantCultureIgnoreCase)); var sd = new StringDistance(); var supportByInstance = (from kvpCult in support from kvpLocIns in kvpCult.Value where filtered(kvpLocIns.Key) let newText = master.GetOrThrow(kvpLocIns.Key) group(lockIns: kvpLocIns.Key, translatedInstance: kvpLocIns.Value, culture: kvpCult.Key, newText: newText) by kvpLocIns.Key.Instance into gInstance select KeyValuePair.Create(gInstance.Key, gInstance.AgGroupToDictionary(a => a.lockIns.RouteAndRowId(), gr => gr.ToDictionary(a => a.culture.Name, a => new TranslatedPairViewTS { OriginalText = a.translatedInstance.OriginalText, Diff = a.translatedInstance.OriginalText.Equals(a.newText) ? null : sd.DiffText(a.translatedInstance.OriginalText, a.newText), TranslatedText = a.translatedInstance.TranslatedText }) ))).ToDictionary(); return(new TranslatedInstanceViewTypeTS { TypeName = type, Routes = TranslatedInstanceLogic.TranslateableRoutes.GetOrThrow(t).ToDictionary(a => a.Key.PropertyString(), a => a.Value), MasterCulture = TranslatedInstanceLogic.DefaultCulture.Name, Instances = master.Where(kvp => filtered(kvp.Key)).GroupBy(a => a.Key.Instance).Select(gr => new TranslatedInstanceViewTS { Lite = gr.Key, Master = gr.ToDictionary( a => a.Key.RouteAndRowId(), a => a.Value ), Translations = supportByInstance.TryGetC(gr.Key) ?? new Dictionary <string, Dictionary <string, TranslatedPairViewTS> >() }).ToList() }); }
public ActionResult View(string type, string culture, bool searchPressed, string filter) { Type t = TypeLogic.GetType(type); ViewBag.Type = t; var c = culture == null ? null : CultureInfo.GetCultureInfo(culture); ViewBag.Culture = c; ViewBag.Filter = filter; if (!searchPressed) { return(base.View(TranslationClient.ViewPrefix.FormatWith("ViewInstance"))); } Dictionary <LocalizedInstanceKey, string> master = TranslatedInstanceLogic.FromEntities(t); ViewBag.Master = master; Dictionary <CultureInfo, Dictionary <LocalizedInstanceKey, TranslatedInstanceEntity> > support = TranslatedInstanceLogic.TranslationsForType(t, culture: c); return(base.View(TranslationClient.ViewPrefix.FormatWith("ViewInstance"), support)); }