public static LibrarylistDto Map(LibraryList list, IRepository documents = null) { if (null != documents) { return new LibrarylistDto { Id = list.Id, Name = list.Name, Documents = list.Documents.Count > 0 ? list.Documents.Select(Map).ToList() : list.DocumentNumbers.Keys.Select(dn => Map(documents.GetDocument(dn, true))).ToList() }; } return new LibrarylistDto { Id = list.Id, Name = list.Name }; }
private static LibraryList FillProperties(XElement xml) { var libList = new LibraryList(); if (xml.Attribute("name") == null) return null; else { var name = xml.Attribute("name"); if (name != null) libList.Name = name.Value; var pri = xml.Attribute("pri"); if (pri != null) { var priAsString = pri.Value; int priAsInt; if (int.TryParse(priAsString, out priAsInt)) { //Set a lowest priority if priority range is invalid (below 0 or above 10) libList.Priority = priAsInt < 1 || priAsInt > 10 ? 10 : priAsInt; } else { //Set a lowest priority if null or wrong type libList.Priority = 10; } } var isRanked = xml.Attribute("ranked"); if (isRanked != null) { libList.IsRanked = isRanked.Value.Equals("true") ? true : false; } xml.Elements().Where(e => e.Name == "docnumber").ToList().ForEach(element => libList.DocumentNumbers.Add(element.Value, false)); } return libList; }