예제 #1
0
        public async Task <ActionResult <Response <ResponseList <Shop> > > > GetShops()
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var shoppingGroup = await _shoppingGroupService.GetActiveShoppingGroupByUserId(user.UserId);

            if (shoppingGroup == null)
            {
                return(Ok(HelperBox.DataToReponseList(true, new List <Shop>())));
            }
            var shops = await _shopService.GetShops(shoppingGroup.Id);

            return(Ok(HelperBox.DataToReponseList(true, shops)));
        }
예제 #2
0
        public async Task <IActionResult> AddProduct([FromBody] ProductRequest productRequest)
        {
            var product = await _productService.AddProduct(productRequest);

            if (product == null)
            {
                return(BadRequest(HelperBox.DataToResponse <object>(false, null, "winkel niet gevonden")));
            }

            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var shoppingGroup = await _shoppingGroupService.GetActiveShoppingGroupByUserId(user.UserId);

            await _shoppingListHub.Clients.Group(shoppingGroup.Id.ToString()).SendAsync(nameof(IMyShoppingListHub.AddProduct), productRequest.ShopId, product);

            return(Ok(HelperBox.DataToResponse(true, "Product is toegevoegd aan de winkel")));
        }
예제 #3
0
        public async Task <ActionResult <Response <ShoppingGroup> > > GetActiveShoppingGroup()
        {
            var token         = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken     = token.Split(' ')[1];
            var user          = UserToken.FromToken(userToken);
            var shoppingGroup = await _shoppingGroupService.GetActiveShoppingGroupByUserId(user.UserId);

            if (shoppingGroup == null)
            {
                return(BadRequest(HelperBox.DataToResponse <ShoppingGroup>(false, null, "Winkelgroep niet gevonden")));
            }
            return(Ok(HelperBox.DataToResponse(true, shoppingGroup)));
        }