public async Task <ActionResult <Response <Shop> > > CreateShop([FromBody] ShopRequest shopRequest)
        {
            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 (String.IsNullOrWhiteSpace(shopRequest.Logo))
            {
                shopRequest.Logo = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.ZkZVmxRirz9VVcxfBZjaqQHaFD%26pid%3DApi&f=1";
            }

            var shop = await _shopService.CreateShop(shoppingGroup.Id, shopRequest);

            if (shop == null)
            {
                return(BadRequest(HelperBox.DataToResponse <Shop>(false, null, "Een winkel heeft een naam en logo nodig")));
            }
            shop.Products = new List <ProductForShop>();

            await _shoppingListHub.Clients.Group(shoppingGroup.Id.ToString()).SendAsync(nameof(IMyShoppingListHub.NewShopCreated), shop);

            return(Ok(HelperBox.DataToResponse(true, shop)));
        }
        public async Task <ActionResult <Response <ResponseList <HomeAutomation.Models.Database.MyCalender.MyCalender> > > > GetMyCalenders()
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            return(Ok(HelperBox.DataToReponseList(true, await _calenderService.GetCalenders(user.UserId))));
        }
        public async Task <ActionResult <Response <string> > > SetDefaultApp([FromBody] AppRequest app)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            return(Ok(await _userService.SetDefaultApp(user.UserId, app.AppId)));
        }
        public async Task <ActionResult <Response <UserInfo> > > GetUserInfo()
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            return(await _userService.GetUserInfo(user.UserId));
        }
Beispiel #5
0
        public async Task <ActionResult <Response <string> > > AddRecipe(int recipeId)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            return(Ok(await _recipeService.SetFavoriteRecipe(user.UserId, recipeId)));
        }
        public async Task <ActionResult <Response <RecipeResponse> > > AddRecipe([FromBody] RecipeRequest recipeRequest)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            return(Ok(await _recipeService.AddRecipe(recipeRequest, user.UserId)));
        }
Beispiel #7
0
        public async Task <ActionResult <Response <ResponseList <ShoppingGroup> > > > GetAllMyShoppingGroups()
        {
            var token          = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken      = token.Split(' ')[1];
            var user           = UserToken.FromToken(userToken);
            var shoppingGroups = await _shoppingGroupService.GetAllShoppingGroupsByUserId(user.UserId);

            return(Ok(HelperBox.DataToReponseList(true, shoppingGroups)));
        }
        public async Task <ActionResult <Response <WorkDay> > > CreateWorkDay([FromBody] WorkDay workDayData)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var workDay = await _workDayService.CreateWorkDay(user.UserId, workDayData);

            return(Ok(HelperBox.DataToResponse(true, workDay)));
        }
        public async Task <ActionResult <Response <ResponseList <WorkDay> > > > GetWorkDays()
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var workDays = await _workDayService.GetWorkDays(user.UserId);

            return(Ok(HelperBox.DataToReponseList(true, workDays)));
        }
Beispiel #10
0
        public async Task <IActionResult> SetActiveShoppingGroup([FromBody] ShoppingGroupRequest shoppingGroupRequest)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            await _shoppingGroupService.SetActiveShoppingGroup(user.UserId, shoppingGroupRequest);

            return(Ok(HelperBox.DataToResponse <string>(true, "winkel groep is nu active")));
        }
Beispiel #11
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)));
        }
        public async Task <ActionResult <Response <HomeAutomation.Models.Database.MyCalender.MyCalender> > > CreateNewCalender([FromBody] MyCalenderRequest newCalender)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var calender = await _calenderService.CreateNewCalender(newCalender, user.UserId);

            if (calender == null)
            {
                return(BadRequest(HelperBox.DataToResponse <object>(false, null, "Naam en Filenaam zijn verplicht")));
            }
            return(Ok(HelperBox.DataToResponse(true, calender)));
        }
Beispiel #13
0
        public async Task <ActionResult <Response <ShoppingGroup> > > AddShoppingGroup([FromBody] ShoppingGroupRequest shoppingGroupRequest)
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var newShoppingGroup = await _shoppingGroupService.CreateShoppingGroup(user.UserId, shoppingGroupRequest);

            if (newShoppingGroup == null)
            {
                return(BadRequest(HelperBox.DataToResponse <ShoppingGroup>(false, null, "Er is geen naam gegeven aan deze winkelgroep")));
            }
            return(Ok(HelperBox.DataToResponse(true, newShoppingGroup)));
        }
        public async Task <ActionResult <Response <ResponseList <object> > > > GetSalaryInMonth()
        {
            var token     = HttpContext.Request.Headers["Authorization"].FirstOrDefault();
            var userToken = token.Split(' ')[1];
            var user      = UserToken.FromToken(userToken);

            var houresInMonth = await _workDayService.GetSalaryInMonth(user.UserId);

            return(Ok(HelperBox.DataToResponse <HouresInMonthResponse>(true, new HouresInMonthResponse()
            {
                HouresList = new ResponseList <object>()
                {
                    List = houresInMonth.Data,
                    Count = houresInMonth.Data.Count(),
                },
                Keys = houresInMonth.Keys
            })));
        }
        public async Task <IActionResult> UpdateProduct(int productShopId, [FromBody] ProductRequest productRequest)
        {
            var product = await _productService.UpdateProduct(productShopId, productRequest.ShopId);

            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.UpdateProduct), productRequest.ShopId, product);

            return(Ok(HelperBox.DataToResponse(true, "Product is geupdate aan de winkel")));
        }
        public async Task <IActionResult> MoveProduct([FromBody] MoveProductRequest moveProductRequest)
        {
            var success = await _productService.MoveProduct(moveProductRequest);

            if (!success)
            {
                return(BadRequest(HelperBox.DataToResponse <string>(false, null, "Product is 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.MoveProduct), moveProductRequest.OldShopId, moveProductRequest.NewShopId, moveProductRequest.ShopProductId);

            return(Ok(HelperBox.DataToResponse(true, "Product is verplaatst")));
        }