public void Populate() { if (Authors.Count() > 0 || Posts.Count() > 0 || SocialNetworkProfiles.Count() > 0) { return; } string jsonData = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/initial-data.json"); var authors = JsonConvert.DeserializeObject <List <Author> >(jsonData); Authors.AddRange(authors); this.SaveChanges(); }
private List <Author> GetMostCommonAuthors(List <Book> books) { List <Author> authors = new List <Author>(); foreach (Book book in books) { authors = authors.Concat(db.BookAuthors.Include("Author") .Where(ba => ba.BookId == book.Id) .Select(ba => ba.Author)) .ToList(); } return(authors.GroupBy(a => a.Id, (id, Authors) => new { Key = id, Count = Authors.Count(), Value = Authors.FirstOrDefault() }).Select(g => g.Value).ToList()); }
public XElement ToXElement() { var locale = LOCALE; var elements = new List <XElement>() { new XElement( XMLNS_NAMESPACE + "id", new XAttribute("advice", "ignore"), new XAttribute("type", "internal"), Id ), new XElement( XMLNS_NAMESPACE + "title", new XAttribute("locale", LOCALE), Title ), }; if (Prefix != "") { elements.Add( new XElement( XMLNS_NAMESPACE + "Prefix", new XAttribute("locale", LOCALE), Prefix ) ); } if (Abstract != "") { elements.Add( new XElement( XMLNS_NAMESPACE + "abstract", new XAttribute("locale", LOCALE), Abstract ) ); } if (LicenseURL != "") { elements.Add( new XElement( XMLNS_NAMESPACE + "licenseUrl", LicenseURL ) ); } var xmlnsnamespace = XMLNS_NAMESPACE; if (Keywords.Length != 0) { elements.Add( new XElement( XMLNS_NAMESPACE + "keywords", new XAttribute("locale", LOCALE), Keywords.Select(el => new XElement( xmlnsnamespace + "keyword", el )).ToArray() ) ); } var xNameSpace = XMLNS_NAMESPACE; if (Authors.Count() != 0) { elements.Add( new XElement( XMLNS_NAMESPACE + "authors", SCHEMA_LOCATION_ATTRIBUTE, XMLNS_XSI_ATTRIBUTE, Authors.Select(el => el.ToXElement(locale, xNameSpace)).ToArray() ) ); } elements.Add( Galley.ToXElement(locale, XMLNS_NAMESPACE, SCHEMA_LOCATION_ATTRIBUTE, XMLNS_XSI_ATTRIBUTE, Stage == "published") ); elements.Add( Identifiaction.ToXElement(XMLNS_NAMESPACE) ); elements.Add( new XElement(XMLNS_NAMESPACE + "pages", Pages) ); return(new XElement( XMLNS_NAMESPACE + "article", SCHEMA_LOCATION_ATTRIBUTE, new XAttribute("access_status", AccessStatus), new XAttribute("seq", Seq), new XAttribute("section_ref", SectionRef), new XAttribute("date_published", DatePublished), new XAttribute("stage", Stage), new XAttribute("date_submitted", DateSubmitted), new XAttribute("locale", locale), XMLNS_XSI_ATTRIBUTE, elements.ToArray() )); }
private string appHelpText() { StringBuilder sb = new StringBuilder(); // NAME sb.Append($"Name: \n"); sb.Append($"\t{Name} {(string.IsNullOrWhiteSpace(Usage) ? "" : "- " + Usage)}"); sb.Append($"\n"); // USAGE sb.Append($"Usage: \n"); sb.Append($"\t{ProcessName}"); if (Flags.Count() > 0) { sb.Append(" [global options]"); } if (Commands.Count() > 0) { sb.Append(" command [command options]"); } if (string.IsNullOrEmpty(ArgsUsage)) { sb.Append(" [arguments...]"); } else { sb.Append(" ").Append(ArgsUsage); } sb.Append($"\n"); // VERSION if (!string.IsNullOrWhiteSpace(Version)) { sb.Append($"Version: \n"); sb.Append($"\t{Version}"); sb.Append($"\n"); } // DESCRIPTION if (!string.IsNullOrWhiteSpace(Description)) { sb.Append($"Description: \n"); sb.Append($"\t{Description}"); sb.Append($"\n"); } // AUTHOR(S) if (Authors.Count() > 0) { if (Authors.Count() > 1) { sb.Append($"Authors: \n").Append("\t"); } else { sb.Append($"Author: \n").Append("\t"); } sb.Append(String.Join(", ", Authors)); sb.Append($"\n"); } // COMMANDS if (Commands.Count() > 0) { sb.Append($"Commands: \n"); int maxLength = Commands.Select(x => String.Join(", ", x.Names()).Length).Max(); foreach (var command in Commands) { string n = String.Join(", ", command.Names()); sb.Append("\t").Append(n).Append(new string(' ', maxLength - n.Length + 1)).Append($" {command.Usage}"); sb.Append($"\n"); } } // GLOBAL OPTIONS if (Flags.Count() > 0) { sb.Append($"Global Options: \n"); int maxLength = Flags.Select(x => String.Join(", ", x.NamesAppendHyphen()).Length).Max(); foreach (var flag in Flags) { string n = String.Join(", ", flag.NamesAppendHyphen()); sb.Append("\t").Append(n).Append(new string(' ', maxLength - n.Length + 1)).Append($" {flag.Usage}"); if (flag.Value is not null) { sb.Append($" (default: \"{flag.Value}\")"); } sb.Append($"\n"); // TODO Value } } // COPYLIGHT if (!string.IsNullOrWhiteSpace(CopyRight)) { sb.Append($"Copyright: \n"); sb.Append($"\t{CopyRight}"); sb.Append($"\n"); } return(sb.ToString()); }