Пример #1
0
        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");
            }
        }
Пример #2
0
        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");
            }
        }
Пример #3
0
        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());
        }
Пример #4
0
 public Task UpdateItem(IdModel shoppingListId, ShoppingItemModel item, CancellationToken cancellationToken)
 {
     return(itemsRepository.UpdateItem(shoppingListId.ToObjectId(), new ShoppingItemDocument(item), cancellationToken));
 }
Пример #5
0
        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));
        }
Пример #6
0
        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());
        }
Пример #7
0
        public async Task <ShoppingListModel> GetShoppingList(IdModel shoppingListId, CancellationToken cancellationToken)
        {
            var shoppingList = await shoppingListCollection.FindDocument(shoppingListId.ToObjectId(), cancellationToken);

            return(shoppingList.ToShoppingListModel());
        }
Пример #8
0
 public Task DeleteItem(IdModel shoppingListId, IdModel itemId, CancellationToken cancellationToken)
 {
     return(itemsRepository.DeleteItem(shoppingListId.ToObjectId(), itemId.ToObjectId(), cancellationToken));
 }
Пример #9
0
        public async Task <ShoppingTemplateModel> GetTemplate(IdModel templateId, CancellationToken cancellationToken)
        {
            var shoppingTemplate = await templatesCollection.FindDocument(templateId.ToObjectId(), cancellationToken);

            return(shoppingTemplate.ToShoppingTemplateModel());
        }