public async Task <IActionResult> Create(ThreadCreateViewModel obj) { if (ModelState.IsValid) { var user = await userManager.FindByNameAsync(User.Identity.Name); GameCommentThread thread = new GameCommentThread { Name = obj.Name, GameId = obj.GameId, Game = _db.Game.Find(obj.GameId), }; GameComment comment = new GameComment { Date = DateTime.Now, Body = obj.Comment.Body, AuthorID = user.Id, Author = user, ThreadId = thread.Id, Thread = thread }; _db.GameComment.Add(comment); _db.SaveChanges(); return(RedirectToAction("Thread", "Forum", new { id = comment.ThreadId })); } return(View(obj)); }
public async Task <IActionResult> AddComment(int id, string comment = null) { var user = await _context.ApplicationUsers.Where(u => u.Email == User.Identity.Name).FirstOrDefaultAsync(); if (user != null) { Comment userComment = new Comment() { ApplicationUserID = user.Id, UserComment = comment, CommentDate = DateTime.Now }; _context.Add(userComment); _context.SaveChanges(); GameComment gameComment = new GameComment() { GameID = id, CommentID = userComment.ID }; _context.Add(gameComment); await _context.SaveChangesAsync(); } else { return(RedirectToAction("Details", "Home", new { area = "Customer", id = id, requireLogin = "******" })); } return(RedirectToAction("Details", "Home", new { area = "Customer", id = id })); }
public async Task Save(GameComment com) { GameComments[com.RepId] = com; var json = JsonSerializer.Serialize(com); string outfile = Program.commentdir + "/" + com.RepId + ".json"; await File.WriteAllTextAsync(outfile, json); }
public ActionResult DeclineGameReview(int id) { GameComment com = db.CommentGames.Find(id); db.CommentGames.Remove(com); db.SaveChanges(); return(RedirectToAction("GameReviewAdminIndex")); }
public ActionResult DeleteConfirmed(int id) { GameComment gameComment = db.GameComments.Find(id); db.GameComments.Remove(gameComment); UpdateRating(gameComment.GameId); db.SaveChanges(); return(RedirectToAction("Details", "Games", new { id = gameComment.GameId })); }
public ActionResult AcceptGameReview(int id) { GameComment com = db.CommentGames.Find(id); db.CommentGames.Remove(com); db.SaveChanges(); (db.DesignedGames.Where(x => x.Id == com.GameId).First()).Comments.Add(com); //db.SaveChanges(); return(RedirectToAction("GameReviewAdminIndex")); }
public ActionResult Edit(GameComment gameComment, int id) { if (ModelState.IsValid) { db.Entry(gameComment).State = EntityState.Modified; UpdateRating(gameComment.GameId); db.SaveChanges(); return(RedirectToAction("Details", "Games", new { id = gameComment.GameId })); } return(View(gameComment)); }
public async Task DeleteComment(int repid, GameComment _com) { string mycomfile = Program.commentdir + "/" + repid + ".bin"; _readWriteLock.EnterWriteLock(); List <GameComment> Gamecoms = new List <GameComment>(await GetComments(repid)); Gamecoms.Remove(_com); WriteToBinaryFile(mycomfile, Gamecoms); _readWriteLock.ExitWriteLock(); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GameComment gameComment = db.GameComments.Find(id); if (gameComment == null) { return(HttpNotFound()); } return(View(gameComment)); }
public ActionResult Create(GameComment gameComment, int id) { if (User.Identity.IsAuthenticated == false) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } if (ModelState.IsValid) { gameComment.Customer = db.Customers.FirstOrDefault(x => x.Login == User.Identity.Name); gameComment.Time = DateTime.Now; gameComment.Game = db.Games.Find(id); db.GameComments.Add(gameComment); UpdateRating(id); db.SaveChanges(); return(RedirectToAction("Details", "Games", new { id = gameComment.GameId })); } return(View(gameComment)); }
public StartUp(DbContextOptions <MMdb> mmdb) { _mmdb = mmdb; _db = new MMdb(_mmdb); foreach (string cmdr in DSdata.s_races) { MMraces.TryAdd(cmdr, new MMplayerNG(cmdr)); } /** * using (var db = new MMdb(_mmdb)) * { * foreach (var ent in db.MMdbPlayers) * db.MMdbPlayers.Remove(ent); * foreach (var ent in db.MMdbRatings) * db.MMdbRatings.Remove(ent); * foreach (var ent in db.MMdbRaceRatings) * db.MMdbRaceRatings.Remove(ent); * * db.SaveChanges(); * } **/ // /** using (var db = new MMdb(_mmdb)) { foreach (var ent in db.MMdbPlayers) { MMplayers[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRaces) { MMraces[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRatings.OrderBy(o => o.Games)) { if (MMplayers.ContainsKey(ent.MMdbPlayer.Name)) { if (MMplayers[ent.MMdbPlayer.Name].AuthName == ent.MMdbPlayer.AuthName) { MMplayers[ent.MMdbPlayer.Name].Rating[ent.Lobby].Add(new MMPlRating(ent)); } } } foreach (var ent in db.MMdbRaceRatings.OrderBy(o => o.Games)) { if (MMraces.ContainsKey(ent.MMdbRace.Name)) { MMraces[ent.MMdbRace.Name].Rating[ent.Lobby].Add(new MMPlRating(ent)); } } } // **/ foreach (string name in MMplayers.Keys) { if (MMplayers[name].AuthName != null && MMplayers[name].AuthName != "") { Players.Add(MMplayers[name].Name); Auth.Add(MMplayers[name].AuthName, MMplayers[name].Name); } } if (!File.Exists(Program.myJson_file)) { File.Create(Program.myJson_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myJson_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { //rep.Init(); repHash.Add(rep.HASH); if (!replays.ContainsKey(rep.ID)) { replays[rep.ID] = new List <dsreplay>(); } replays[rep.ID].Add(rep); } } if (!File.Exists(Program.myReplays_file)) { File.Create(Program.myReplays_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myReplays_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { MyReplays.Add(rep); } } string exedir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Exedir = exedir; foreach (var file in Directory.EnumerateFiles(Program.replaydir)) { string dest = exedir + "/replays/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } foreach (var file in Directory.EnumerateFiles(Program.myreplaydir)) { string dest = exedir + "/replays/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } foreach (var dir in Directory.EnumerateDirectories(Program.workdir + "/tournaments")) { string tourny = Path.GetFileName(dir); if (File.Exists(dir + "/treplays.json")) { TournamentReplays.Add(tourny, new List <dsreplay>()); foreach (var line in File.ReadAllLines(dir + "/treplays.json")) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { TournamentReplays[tourny].Add(rep); } } if (!Directory.Exists(Exedir + "/treplays/" + tourny)) { Directory.CreateDirectory(Exedir + "/treplays/" + tourny); } foreach (var file in Directory.EnumerateFiles(dir + "/replays")) { string dest = Exedir + "/treplays/" + tourny + "/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } } if (File.Exists(dir + "/info.json")) { TournamentInfo t = JsonSerializer.Deserialize <TournamentInfo>(File.ReadAllText(dir + "/info.json")); TournamentInfo[tourny] = t; } } foreach (var file in Directory.EnumerateFiles(Program.commentdir)) { GameComment com = JsonSerializer.Deserialize <GameComment>(File.ReadAllText(file)); if (com != null) { GameComments[com.RepId] = com; } } // ladder init //LadderInit(); }