public async Task <IActionResult> NewTopicF([Bind("Title,Content, UserName, DT, CategoryID")] Post post)
        {
            if (ValidateCheck(post.Content) == true)
            {
                ViewData["Alert"] = "Please Remove The Special Characters.";
            }
            else
            {
                if (ModelState.IsValid)
                {
                    //Take in user object
                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    ////For username (can use it inside method also)
                    var username = user;
                    post.UserName = user.UserName;
                    post.DT       = DateTime.Now;

                    context1.Add(post);
                    await context1.SaveChangesAsync();

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

            PopulateCategoryDropDownList();
            return(View(post));
        }
예제 #2
0
 public IActionResult CreateCategory(Categories newCategory)
 {
     if (ModelState.IsValid)
     {
         if (!_context.categories.Any(c => c.Name == newCategory.Name))
         {
             Categories new_category = new Categories
             {
                 Name = newCategory.Name,
             };
             _context.Add(new_category);
             _context.SaveChanges();
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError("Name", "This category already exists.");
     }
     ViewBag.UserName   = _userManager.GetUserName(HttpContext.User);
     ViewBag.Categories = _context.categories.Include(c => c.Moderators).ThenInclude(m => m.User).Include(c => c.Topics);
     ViewBag.Role       = false;
     if (HttpContext.User.IsInRole("Level2"))
     {
         ViewBag.Role = true;
     }
     return(View("Index"));
 }
예제 #3
0
        public async Task <IActionResult> New(int postID, [Bind("Details,Reason,EndTime")] Ban ban)
        {
            ban.Post = _context.Posts
                       .Include(p => p.User)
                       .Where(p => p.ID == postID)
                       .FirstOrDefault();
            ban.Moderator = await _userManager.GetUserAsync(User);

            if (!String.IsNullOrWhiteSpace(ban.Details) || ban.Reason != null)
            {
                _context.Add(ban);

                var reports = _context.Reports.Where(r => r.Post.ID == postID);

                foreach (var report in reports)
                {
                    _context.Update(report);
                    report.Active = false;
                }

                await _context.SaveChangesAsync();

                var users = _context.Posts
                            .Where(p => p.IP == ban.Post.IP && p.User != null)
                            .Select(p => p.User)
                            .ToList();
                foreach (var user in users)
                {
                    if (!await _userManager.IsInRoleAsync(user, "Admin"))
                    {
                        await _userManager.RemoveFromRoleAsync(user, "Moderator");
                    }
                }

                return(RedirectToAction("Index", "Home"));
            }

            return(View(ban));
        }
        public int InsertOrUpdate(Comentario comentario)
        {
            var _comentario = _forumContext.Comentario.FirstOrDefault(x => x.ComentarioId == comentario.ComentarioId);

            if (_comentario == null)
            {
                _comentario = new Comentario();
            }


            _comentario.Autor        = comentario.Autor;
            _comentario.Texto        = comentario.Texto;
            _comentario.PostId       = comentario.PostId;
            _comentario.DataCadastro = comentario.DataCadastro;

            _forumContext.Add(_comentario);
            _forumContext.SaveChanges();

            return(_comentario.ComentarioId);
        }