예제 #1
0
        public async Task <IActionResult> AddGrocery([FromBody] GroceryItem grocery, [FromRoute] int shopId)
        {
            var newGroceryItem = await _grocceryItemService.AddItemToList(shopId, grocery);

            if (newGroceryItem == null)
            {
                return(BadRequest(new BaseResponse <string>()
                {
                    Succes = false,
                    Error = "no shop found with this shopId"
                }));
            }

            var signalrRoom = await _grocceryItemService.GetSignalrRoom(shopId);

            if (signalrRoom == null)
            {
                return(BadRequest(new BaseResponse <string>()
                {
                    Succes = false,
                    Error = "No signalr group found for this grocery list"
                }));
            }
            var shopResponse = await _shopService.GetShopByShopId(shopId);

            await _groceryItemHub.Clients.Group(signalrRoom).SendAsync(nameof(IGroceryItemHub.NewGroceryAdded), newGroceryItem);

            await _shopHub.Clients.Group("Test-5").SendAsync(nameof(IShopHub.UpdateShop), shopResponse);

            return(Created("https://shoppinglist.dallau.com", newGroceryItem));
        }