Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "NewsGroupId,GroupTitle,ParentId,IsActive,AliasName")] NewsGroup newsGroup)
        {
            if (ModelState.IsValid)
            {
                if (newsGroup.ParentId == 0)
                {
                    newsGroup.Depth = 0;
                    newsGroup.Path  = "0";
                }
                else
                {
                    var newsGroupParent = _newsGroupService.GetById(newsGroup.ParentId);
                    newsGroup.Depth = newsGroupParent.Depth + 1;
                    newsGroup.Path  = newsGroupParent.NewsGroupId + "/" + newsGroupParent.Path;
                }
                _newsGroupService.Add(newsGroup);
                return(RedirectToAction("Index"));
            }

            return(View(newsGroup));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("NewsGroupId,GroupTitle,Depth,Path,IsActive,DisplayOrder,ParentId,AliasName,AddedDate,ModifiedDate,IP")] NewsGroup newsGroup)
        {
            if (ModelState.IsValid)
            {
                if (newsGroup.ParentId == 0)
                {
                    newsGroup.Depth = 0;
                    newsGroup.Path  = "0";
                }
                else
                {
                    var newsGroupParent = await _newsGroupService.GetById(newsGroup.ParentId);

                    newsGroup.Depth = newsGroupParent.Depth + 1;
                    newsGroup.Path  = newsGroupParent.NewsGroupId + "/" + newsGroupParent.Path;
                }
                await _newsGroupService.Add(newsGroup);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(newsGroup));
        }