Beispiel #1
0
        public async Task <IActionResult> ExecuteAsync(int menuItemId, SaveMenuItem saveMenuItem, CancellationToken cancellationToken)
        {
            var menuItem = await _menuItemRepository.Get(menuItemId, cancellationToken);

            if (menuItem == null)
            {
                return(new NotFoundResult());
            }
            _saveMenuItemToMenuItemMapper.Map(saveMenuItem, menuItem);

            var listMenuItemId = await getListMenuItemId(new List <int>(), menuItem.Id, cancellationToken);

            var menuItems = await _menuItemRepository.GetMenuItemsByListId(listMenuItemId, cancellationToken);

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

            //var claims = user.Claims.ToList();
            //if (claims.Count < 1)
            //    return new NotFoundResult();
            //// Lấy Id của người dùng
            //var userId = claims.FirstOrDefault(claimRecord => claimRecord.Type == "sub").Value;

            foreach (var item in menuItems)
            {
                item.Active = saveMenuItem.Active;
                //item.ModifiedBy = userId;
                await _menuItemRepository.Update(item, cancellationToken);
            }
            var menuItemViewModel = _menuItemToMenuItemMapper.Map(menuItem);

            return(new OkObjectResult(menuItemViewModel));
        }
        public async Task <IActionResult> ExecuteAsync(int menuItemId, CancellationToken cancellationToken)
        {
            var menuItem = await _menuItemRepository.Get(menuItemId, cancellationToken);

            if (menuItem == null)
            {
                return(new NoContentResult());
            }

            var listMenuItemId = await getListMenuItemId(new List <int>(), menuItem.Id, cancellationToken);

            var menuItems = await _menuItemRepository.GetMenuItemsByListId(listMenuItemId, cancellationToken);

            await _menuItemRepository.DeleteRange(menuItems, cancellationToken);

            return(new NoContentResult());
        }