Exemple #1
0
        public async Task <IActionResult> ExecuteAsync(int menuId, SaveMenuItem saveMenuItem, CancellationToken cancellationToken)
        {
            var menu = await _menuItemRepository.GetMenuId(menuId, cancellationToken);

            if (menu == null)
            {
                return(new NoContentResult());
            }
            saveMenuItem.MenuId = menuId;
            var menuItem = _saveMenuItemToMenuItemMapper.Map(saveMenuItem);

            //var user = _httpContextAccessor.HttpContext.User;
            //if (user == null)
            //    return new NotFoundResult();

            //var claims = user.Claims.ToList();
            //if (claims.Count < 1)
            //    return new NotFoundResult();

            //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub").Value;
            //menuItem.CreatedBy = userId;
            //menuItem.ModifiedBy = userId;

            menuItem = await _menuItemRepository.Add(menuItem, cancellationToken);

            var menuItemViewModel = _menuItemToMenuItemMapper.Map(menuItem);

            return(new CreatedAtRouteResult(MenuItemsControllerRoute.GetMenuItem,
                                            new { id = menuItemViewModel.Id },
                                            menuItemViewModel));
        }