public ActionResult Moderation(string status, string serverid, string password) { ModerationViewModel viewModel = new ModerationViewModel(); using SqlConnection conn = new SqlConnection(ConfigClass.connectionString); using SqlCommand query = new SqlCommand($"select Password from [dbo].[servers] where ServerId = '{serverid}'", conn); conn.Open(); var reader = query.ExecuteReader(); while (reader.Read()) { string RealPassword = reader.GetString(0); if (RealPassword == password) { conn.Close(); using SqlCommand updateQuery = new SqlCommand($"update [dbo].[servers] set ModerationEnabled = '{status.ToString()}' where ServerId = '{serverid}'", conn); conn.Open(); updateQuery.ExecuteReader(); TempData["UpdateSuccess"] = "<script>alert('The settings have been updated.');</script>"; return(RedirectToAction("Index", "Home")); } } conn.Close(); return(View()); }
public IActionResult Index(string query = null, int page = 1, int pageSize = 25, bool today = false, bool total = false) { var illegalObjects = _context.IllegalObjects .Include(x => x.Status) .Where(x => x.DeletedAt == null) .OrderByDescending(x => x.CreatedAt) .Select(x => new IllegalObjectViewModel { IllegalObjectId = x.IllegalObjectId, Address = x.Address, Description = x.Description, Infringement = x.Infringement, ResultsOfReview = x.ResultsOfReview, StatusId = x.StatusId, StatusName = x.Status.IllegalObjectStatusName, StatusColor = x.Status.IllegalObjectColor, CreatedAt = x.CreatedAt, ApprovedAt = x.ApprovedAt }); var totalObjects = illegalObjects.Count(); var notApprovedTotal = illegalObjects.Count(x => x.ApprovedAt == null); var notApprovedToday = illegalObjects.Count(x => x.ApprovedAt == null && (x.CreatedAt != null && x.ApprovedAt != null && x.CreatedAt.Value.Date == DateTime.Now.Date)); if (query != null) { illegalObjects = illegalObjects.Where(x => x.Address.Contains(query)); } if (total) { illegalObjects = illegalObjects.Where(x => x.ApprovedAt == null); } if (today) { illegalObjects = illegalObjects.Where(x => x.ApprovedAt == null && (x.CreatedAt != null && x.ApprovedAt != null && x.CreatedAt.Value.Date == DateTime.Now.Date)); } var illegalObjectsList = illegalObjects .Skip((page - 1) * pageSize) .Take(pageSize) .AsNoTracking() .ToList(); var viewModel = new ModerationViewModel { IllegalObjects = illegalObjectsList, PagesCount = (int)Math.Ceiling((double)illegalObjects.Count() / pageSize), PageSize = pageSize, CurrentPage = page, Query = query, Total = totalObjects, NotApprovedTotal = notApprovedTotal, NotApprovedToday = notApprovedToday, IsNotApprovedTodayList = today, IsNotApprovedTotalList = total }; return(View(viewModel)); }