public override void GenTest(List <Ref> ARefs = null) { String[] LCBooks = new String[] { "Название Книги 1 Текст" , "Название Книги 2 Текст" , "Название Книги 3 Текст" , "Название Книги 4 Текст" , "Название Книги 5 Текст" , "Название Книги 6 Текст" }; Random Rnd = new Random(); for (int i = 0; i < TestDataCount; i++) { int LIndx = Rnd.Next(0, LCBooks.Length); LBBook LItem = new LBBook(); LItem.Id = i + 1; LItem.Name = LCBooks[LIndx]; if (null != ARefs) { if (ARefs.Count > 0) { int LRandomAuthorIndex = Rnd.Next(0, ARefs[0].Count); LItem.Author = (LBAuthor)ARefs[0][LRandomAuthorIndex]; } } LItem.ISBN = "2-266-11156-6" + i.ToString(); Add(LItem); } }
public override RefItem LoadFromJSONItem(dynamic AJSONObject, List <Ref> ARefs = null) { LBBook LResult = new LBBook(); foreach (var LProperty in AJSONObject) { if (((String)LProperty.Name).Equals("Id")) { LResult.Id = LProperty.Value; } if (((String)LProperty.Name).Equals("Name")) { LResult.Name = LProperty.Value; } if (((String)LProperty.Name).Equals("ISBN")) { LResult.ISBN = LProperty.Value; } RefItem LAuthor = null; if (((String)LProperty.Name).Equals("Author")) { int LAuthorId = 0; String LAuthorName = ""; foreach (var LAuthorProp in LProperty.Value) { if (((String)LAuthorProp.Name).Equals("Id")) { LAuthorId = LAuthorProp.Value; } if (((String)LAuthorProp.Name).Equals("Name")) { LAuthorName = LAuthorProp.Value; } } if (null != ARefs) { if (ARefs.Count > 0) { foreach (RefItem LItem in ARefs[0]) { if ((LItem.Id == LAuthorId) && (LItem.Name.Equals(LAuthorName))) { LAuthor = LItem; break; } } if (null == LAuthor) { LAuthor = new LBAuthor(); LAuthor.Id = LAuthorId; LAuthor.Name = LAuthorName; ARefs[0].Add(LAuthor); } } } } if (null != LAuthor) { LResult.Author = LAuthor; } } return(LResult); }