public int InsertOrUpdateItem(CreateOrUpdateItemDto item) { if (item.CategoryId <= 0) { throw new ArgumentException("Please set the category id before insert or update"); } return(_dbRepo.InsertOrUpdateItem(_mapper.Map <Item>(item))); }
private static void CreateMultipleItems(IItemsService svc) { Console.WriteLine("Would you like to create items as a batch?"); bool batchCreate = Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase); var allItems = new List <CreateOrUpdateItemDto>(); bool createAnother = true; while (createAnother == true) { var newItem = new CreateOrUpdateItemDto(); Console.WriteLine("Creating a new item."); Console.WriteLine("Please enter the name"); newItem.Name = Console.ReadLine(); Console.WriteLine("Please enter the description"); newItem.Description = Console.ReadLine(); Console.WriteLine("Please enter the notes"); newItem.Notes = Console.ReadLine(); Console.WriteLine("Please enter the Category [B]ooks, [M]ovies, [G]ames"); newItem.CategoryId = GetCategoryId(Console.ReadLine().Substring(0, 1).ToUpper()); if (!batchCreate) { svc.InsertOrUpdateItem(newItem); } else { allItems.Add(newItem); } Console.WriteLine("Would you like to create another item?"); createAnother = Console.ReadLine().StartsWith("y", StringComparison.OrdinalIgnoreCase); if (batchCreate && !createAnother) { svc.InsertOrUpdateItems(allItems); } } }