private static void TestRelations() { IDataParameter parameter = new SqlParameter("@ItemID", 3); ItemRelationshipsDto dto = ItemDao.GetRelations(parameter); Console.WriteLine($"Here is the relationships for: {Environment.NewLine + Environment.NewLine} {dto.Item.Name} {Environment.NewLine + Environment.NewLine}"); foreach (IItemRelation relation in dto.Relations) { if (relation.ItemOneId == dto.Item.Id) { IItem relatedItem = dto.Items.FirstOrDefault(item => item.Id == relation.ItemTwoId); Console.WriteLine($"{dto.Item.Name} has a downstream dependency to {relatedItem.Name}."); } else { IItem relatedItem = dto.Items.FirstOrDefault(item => item.Id == relation.ItemOneId); Console.WriteLine($"{dto.Item.Name} has a upstream dependency to {relatedItem.Name}."); } } Console.Read(); }
// GET: api/Item/GetItemRelations public JsonResult <ItemRelationshipsDto> GetRelations(int itemId) { ItemService service = new ItemService(); ItemRelationshipsDto dto = service.GetItemRelations(itemId); return(Json(dto)); }
private static void TestItems() { while (true) { Console.WriteLine("Enter any number between 1 and 13; type 'exit' to quit."); string input = Console.ReadLine(); if (input.Equals("exit", StringComparison.OrdinalIgnoreCase)) { break; } int id = Convert.ToInt32(input); IDataParameter parameter = new SqlParameter("@ItemID", id); IItem selectedItem = ItemDao.Get(parameter); Console.WriteLine($"You have selected {selectedItem.Name} {Environment.NewLine}"); ItemRelationshipsDto dto = ItemDao.GetRelations(parameter); foreach (IItemRelation relation in dto.Relations) { if (relation.ItemOneId == selectedItem.Id) { IItem relatedItem = dto.Items.FirstOrDefault(item => item.Id == relation.ItemTwoId); Console.WriteLine($"{selectedItem.Name} has a downstream dependency to {relatedItem.Name}."); } else { IItem relatedItem = dto.Items.FirstOrDefault(item => item.Id == relation.ItemOneId); Console.WriteLine($"{selectedItem.Name} has a upstream dependency to {relatedItem.Name}."); } } Console.WriteLine(Environment.NewLine + Environment.NewLine + "----------------------------------------------------------"); } }