public async Task <GroceryItem> AddGroceryItem(AddGroceryItemDto newGroceryItem) { GroceryItem groceryItem = _mapper.Map <GroceryItem>(newGroceryItem); groceryItem.Category = await _context.GroceryCategories.FirstAsync(c => c.Id == newGroceryItem.GroceryCategoryId); await _context.GroceryItems.AddAsync(groceryItem); await _context.SaveChangesAsync(); return(groceryItem); }
public void AddGroceryItem_MinimalGroceryItem_NoErrors() { AddGroceryItemDto groceryItemDto = new AddGroceryItemDto() { GroceryCategoryId = CategoryId, Name = "item name" }; Assert.DoesNotThrowAsync(async() => { await _groceryItemRepository.AddGroceryItem(groceryItemDto); }); }
public async Task <IActionResult> AddGroceryItem(AddGroceryItemDto newGroceryItem) { return(Ok(await _groceryItemRepository.AddGroceryItem(newGroceryItem))); }