public override async Task <ShoppingListItemReply> AddShoppingListItem(AddShoppingListItemRequest request, ServerCallContext context)
        {
            var shoppingList = await _repository.Find(request.ShoppingListId);

            if (shoppingList == null)
            {
                throw new RpcException(new Status(StatusCode.NotFound, "Shopping list not found"));
            }

            shoppingList.Items.Add(new ShoppingListItem
            {
                Name   = request.Name,
                Amount = request.Amount,
                Unit   = (Domain.Unit)(int) request.Unit
            });

            await _repository.Save(shoppingList);

            return(AsReply(shoppingList.Items.LastOrDefault()));
        }
Beispiel #2
0
        private void ToggleShoppingListItem(string message)
        {
            Console.WriteLine("ShoppingListItemRemove");
            List <object> deserializedMessage = _pubnub.JsonPluggableLibrary.DeserializeToListOfObject(message);
            var           shoppingListItem    = JsonConvert.DeserializeObject <ShoppingListItemDto>(deserializedMessage[0].ToString());

            var item = _repo.GetItem(shoppingListItem.id);

            item.complete = shoppingListItem.complete;

            _repo.Save(item);
        }