/// <summary>
        /// Moves navigations towards provided direction.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="direction"></param>
        /// <returns>Tuple of bool and string.</returns>
        public async Task <(bool, string)> MoveNavigationAsync(int id, MoveNavi direction)
        {
            if (id != 0)
            {
                PortfolioNavigation navigation = await _dbContext.PortfolioNavigations.SingleOrDefaultAsync(x => x.Id == id);

                if (navigation != null)
                {
                    if (direction == MoveNavi.Down)
                    {
                        if (navigation.Order == _dbContext.PortfolioNavigations.Count())
                        {
                            return(false, "Error: Navigation is already at the end.");
                        }

                        PortfolioNavigation nextNavigation = await _dbContext.PortfolioNavigations.SingleOrDefaultAsync(x => x.Order == navigation.Order + 1);

                        if (nextNavigation != null)
                        {
                            nextNavigation.Order = nextNavigation.Order - 1;
                            _dbContext.PortfolioNavigations.Update(nextNavigation);

                            navigation.Order = navigation.Order + 1;
                            _dbContext.PortfolioNavigations.Update(navigation);

                            await _dbContext.SaveChangesAsync();

                            return(true, "Navigation moved down.");
                        }
                        return(false, "Error: Next navigation not found.");
                    }
                    else if (direction == MoveNavi.Up)
                    {
                        if (navigation.Order == 1)
                        {
                            return(false, "Error: Navigation is already at the top.");
                        }

                        PortfolioNavigation previousNavigation = await _dbContext.PortfolioNavigations.SingleOrDefaultAsync(x => x.Order == navigation.Order - 1);

                        if (previousNavigation != null)
                        {
                            previousNavigation.Order = previousNavigation.Order + 1;
                            _dbContext.PortfolioNavigations.Update(previousNavigation);

                            navigation.Order = navigation.Order - 1;
                            _dbContext.PortfolioNavigations.Update(navigation);

                            await _dbContext.SaveChangesAsync();

                            return(true, "Navigation moved up.");
                        }
                        return(false, "Error: Previous navigation not found");
                    }
                }
            }
            return(false, "Error: Item not found");
        }
        /// <summary>
        /// Adds navigation item.
        /// </summary>
        /// <param name="navigation"></param>
        /// <returns>Tuple of bool and string.</returns>
        public async Task <(bool, string)> AddNavigationAsync(PortfolioNavigation navigation)
        {
            if (navigation != null)
            {
                int order = _dbContext.PortfolioNavigations.Count();
                navigation.Order = order + 1;

                _dbContext.PortfolioNavigations.Add(navigation);
                await _dbContext.SaveChangesAsync();

                return(true, "Page added successfully");
            }
            return(false, "Null object provided.");
        }
        /// <summary>
        /// Updates navigation item.
        /// </summary>
        /// <param name="navigation"></param>
        /// <returns>Tuple of bool and string.</returns>
        public async Task <(bool, string)> UpdateNavigationAsync(PortfolioNavigation navigation)
        {
            if (navigation != null)
            {
                PortfolioNavigation dbNavigation = await _dbContext.PortfolioNavigations.SingleOrDefaultAsync(x => x.Id == navigation.Id);

                if (dbNavigation != null)
                {
                    dbNavigation.Name = navigation.Name;
                    dbNavigation.Url  = navigation.Url;

                    _dbContext.PortfolioNavigations.Update(dbNavigation);
                    await _dbContext.SaveChangesAsync();

                    return(true, "Navigation item updated successfully.");
                }

                return(false, "Item not found.");
            }
            return(false, "Null object provided.");
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id != null)
            {
                PortfolioNavigation navigation = await _navigationService.GetNavigationByIdAsync((int)id);

                if (navigation != null)
                {
                    Input      = new InputModel();
                    Input.Id   = navigation.Id;
                    Input.Name = navigation.Name;
                    Input.Url  = navigation.Url;

                    return(Page());
                }

                StatusMessage = "Error: Item not found";
                return(LocalRedirect("/Admin/NavigationEditor"));
            }

            StatusMessage = "Error: Item not found";
            return(LocalRedirect("/Admin/NavigationEditor"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                PortfolioNavigation navigation = new PortfolioNavigation();

                navigation.Name = Input.Name;
                navigation.Url  = Input.Url;

                (bool, string)result = await _navigationService.AddNavigationAsync(navigation);

                if (result.Item1)
                {
                    StatusMessage = result.Item2;
                    return(LocalRedirect("/Admin/NavigationEditor"));
                }
                else
                {
                    ErrorMessage = "Error:" + result.Item2;
                }
            }
            return(Page());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (ModelState.IsValid)
            {
                PortfolioNavigation navigation = new PortfolioNavigation();

                navigation.Id = Input.Id;

                navigation.Name = Input.Name;
                navigation.Url  = Input.Url;

                (bool, string)result = await _navigationService.UpdateNavigationAsync(navigation);

                if (result.Item1)
                {
                    StatusMessage = result.Item2;
                }
                else
                {
                    StatusMessage = "Error:" + result.Item2;
                }
            }
            return(Page());
        }
        /// <summary>
        /// Deletes Navigation item by id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <(bool, string)> DeleteNavigationByIdAsync(int id)
        {
            if (id != 0)
            {
                PortfolioNavigation navigation = await _dbContext.PortfolioNavigations.SingleOrDefaultAsync(x => x.Id == id);

                if (navigation != null)
                {
                    List <PortfolioNavigation> navigationsList = await _dbContext.PortfolioNavigations.Where(x => x.Order > navigation.Order).ToListAsync();

                    for (int i = 0; i < navigationsList.Count; i++)
                    {
                        navigationsList[i].Order = navigationsList[i].Order - 1;
                        _dbContext.PortfolioNavigations.Update(navigationsList[i]);
                    }

                    _dbContext.PortfolioNavigations.Remove(navigation);
                    await _dbContext.SaveChangesAsync();

                    return(true, "Navigation item deleted successfully.");
                }
            }
            return(false, "Item not found.");
        }