public bool UpdateWord(Word updatedWord) { try { using (HangmanContext context = new HangmanContext()) { Word word = context.Words.FirstOrDefault(w => w.WordID == updatedWord.WordID); word = updatedWord; context.SaveChanges(); } return(true); } catch (Exception ex) { string path = HttpContext.Current.Server.MapPath("~/Logs"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } System.IO.File.AppendAllText(System.IO.Path.Combine(path, "Words.txt"), "Error: " + DateTime.Now.ToString() + " " + ex.ToString() + Environment.NewLine); return(false); } }
public bool AddEntry(Review entry) { try { using (HangmanContext context = new HangmanContext()) { entry.DateCreated = DateTime.Now; entry.IsApproved = true; context.Reviews.Add(entry); context.SaveChanges(); } return(true); } catch (Exception ex) { string path = HttpContext.Current.Server.MapPath("~/Logs"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } System.IO.File.AppendAllText(System.IO.Path.Combine(path, "Review.txt"), "Error: " + DateTime.Now.ToString() + " " + ex.ToString() + Environment.NewLine); return(false); } }
public void AddScoreBoard(ScoreBoard scoreBoard) { using (var context = new HangmanContext()) { context.ScoreBoards.Add(scoreBoard); context.SaveChanges(); } }
public void Update(Player entity) { using (var context = new HangmanContext()) { context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); } }
public void Delete(int key) { using (var context = new HangmanContext()) { var entity = context.Players.Find(key); context.Players.Remove(entity); context.SaveChanges(); } }
public int SaveResult(HangmanResult result) { try { using (HangmanContext context = new HangmanContext()) { if (result.ResultID == 0) { result.PlayDate = DateTime.Now; context.HangmanResults.Add(result); context.SaveChanges(); } else { HangmanResult updateResult = context.HangmanResults.FirstOrDefault(r => r.ResultID == result.ResultID); updateResult.PlayDate = DateTime.Now; updateResult.WrongAssumption = result.WrongAssumption; updateResult.IsWinner = result.IsWinner; if (result.WordID != 0) { updateResult.WordID = result.WordID; } context.SaveChanges(); } } return(result.ResultID); } catch (Exception ex) { string path = HttpContext.Current.Server.MapPath("~/Logs"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } System.IO.File.AppendAllText(System.IO.Path.Combine(path, "Hangman.txt"), "Error: " + DateTime.Now.ToString() + " " + ex.ToString() + Environment.NewLine); return(0); } }
public static int RegisterAccount(Account account) { using (HangmanContext context = new HangmanContext()) { context.Accounts.Add(account); context.SaveChanges(); } return(account.AccountID); }
public Result <UserStatisticsDto> UpdateStatistics(int id, [NotNull] UserStatisticsDto model) { _logger.Information("UpdateStatistics requested by anonymous"); try { var dbModel = _mapper.Map <UserStatisticsDb>(model); _context.UserStatistics.Attach(dbModel); var entry = _context.Entry(dbModel); entry.State = EntityState.Modified; _context.SaveChanges(); //UPDATE return(Result.Success(model)); } catch (DbUpdateException ex) { _logger.Error("Connection to db is failed", ex); return(Result.Failure <UserStatisticsDto>(ex.Message)); } }
public int Add(Player entity) { var key = 0; using (var context = new HangmanContext()) { context.Players.Add(entity); context.SaveChanges(); key = entity.PlayerId; } return(key); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new HangmanContext( serviceProvider.GetRequiredService < DbContextOptions <HangmanContext> >())) { // Look for any Words if (context.WordInfos.Any()) { return; // DB has been seeded } context.WordInfos.AddRange( new WordInfo { Word = "Test", DateSubmitted = DateTime.MaxValue, IsApproved = true, Language = new Language { Games = new List <Game>(), LanguageId = 0, LanguageName = "Java", Letters = new List <LetterInfo>(), Words = new List <WordInfo>() }, LanguageId = 0, Submitter = new User { Games = new List <Game>(), IsAdmin = true, Mail = "*****@*****.**", Password = "******", UserId = 1, Username = "******", WordApprovals = new List <WordApproval>(), Words = new List <WordInfo>() }, SubmitterId = 1, WordApprovals = new List <WordApproval>(), WordId = 0, WordInGames = new List <WordInGame>() } ); context.SaveChanges(); } }