예제 #1
0
        public IActionResult DeleteConfirmed(int id)
        {
            var relatedPages = this._context.Get(id);

            _context.Remove(relatedPages);
            return(RedirectToAction("Index"));
        }
예제 #2
0
        public IActionResult AddRelations(int id, List <RelPagesView> list)
        {
            if (ModelState.IsValid)
            {
                _logger.LogInformation(id.ToString());
                var relPages = _related.GetAll();
                for (int i = 0; i < list.Count; i++)
                {
                    var item    = list[i];
                    var relpage = relPages.FirstOrDefault(r => (r.Page1Id == id && r.Page2Id == item.RelPageId) || (r.Page1Id == item.RelPageId && r.Page2Id == id));

                    if (relpage == null && item.IsSelected)
                    {
                        _related.Add(new RelatedPages()
                        {
                            Page1Id = id, Page2Id = item.RelPageId
                        });
                    }
                    else if (relpage != null && !item.IsSelected)
                    {
                        _related.Remove(relpage);
                    }
                }
                return(RedirectToAction("Index"));
            }
            var related = _related.GetAll().Where(r => r.Page1Id == id || r.Page2Id == id).Select(r => r.Page1Id == id ? r.Page2Id : r.Page1Id).ToList();

            var res = _repo.GetAll()
                      .Where(r => r.PageId != id)
                      .Select(r => new RelPagesView()
            {
                RelPageId  = r.PageId,
                IsSelected = related.Contains(r.PageId),
                Name       = r.UrlName
            })
                      .ToList();

            return(View(res));
        }