public async Task DeleteShoppingList(IdModel shoppingListId, CancellationToken cancellationToken) { var filter = shoppingListId.ToObjectId().BuildDocumentFilter <ShoppingListDocument>(); var deleteResult = await shoppingListCollection.DeleteOneAsync(filter, cancellationToken); if (deleteResult.DeletedCount != 1) { throw new NotFoundException($"The shopping list with id {shoppingListId} was not found"); } }
public async Task DeleteTemplate(IdModel templateId, CancellationToken cancellationToken) { var filter = templateId.ToObjectId().BuildDocumentFilter <ShoppingTemplateDocument>(); var deleteResult = await templatesCollection.DeleteOneAsync(filter, cancellationToken); if (deleteResult.DeletedCount != 1) { throw new NotFoundException($"The template with id {templateId} was not found"); } }
public async Task <IdModel> CreateItem(IdModel shoppingListId, ShoppingItemModel item, CancellationToken cancellationToken) { var newItem = new ShoppingItemDocument(item) { Id = ObjectId.GenerateNewId(), }; await itemsRepository.CreateItem(shoppingListId.ToObjectId(), newItem, cancellationToken); return(newItem.Id.ToIdModel()); }
public Task UpdateItem(IdModel shoppingListId, ShoppingItemModel item, CancellationToken cancellationToken) { return(itemsRepository.UpdateItem(shoppingListId.ToObjectId(), new ShoppingItemDocument(item), cancellationToken)); }
public Task SetItems(IdModel shoppingListId, IEnumerable <ShoppingItemModel> items, CancellationToken cancellationToken) { var documentItems = items.Select(x => new ShoppingItemDocument(x)); return(itemsRepository.SetItems(shoppingListId.ToObjectId(), documentItems, cancellationToken)); }
public async Task <IReadOnlyCollection <ShoppingItemModel> > GetItems(IdModel shoppingListId, CancellationToken cancellationToken) { var items = await itemsRepository.GetItems(shoppingListId.ToObjectId(), cancellationToken); return(items.Select(x => x.ToModel()).ToList()); }
public async Task <ShoppingListModel> GetShoppingList(IdModel shoppingListId, CancellationToken cancellationToken) { var shoppingList = await shoppingListCollection.FindDocument(shoppingListId.ToObjectId(), cancellationToken); return(shoppingList.ToShoppingListModel()); }
public Task DeleteItem(IdModel shoppingListId, IdModel itemId, CancellationToken cancellationToken) { return(itemsRepository.DeleteItem(shoppingListId.ToObjectId(), itemId.ToObjectId(), cancellationToken)); }
public async Task <ShoppingTemplateModel> GetTemplate(IdModel templateId, CancellationToken cancellationToken) { var shoppingTemplate = await templatesCollection.FindDocument(templateId.ToObjectId(), cancellationToken); return(shoppingTemplate.ToShoppingTemplateModel()); }