public DateTime?UpdateNote(IPwdManService pwdManService, string authenticationToken, NoteModel noteModel) { logger.LogDebug("Update note ID {noteModel.Id}...", noteModel.Id); var user = pwdManService.GetUserFromToken(authenticationToken); var dbContext = pwdManService.GetDbContext(); var note = dbContext.DbNotes.SingleOrDefault( (n) => n.Id == noteModel.Id && n.DbUserId == user.Id); if (note != null && (note.Title != noteModel.Title || note.Content != noteModel.Content)) { note.Title = noteModel.Title; note.Content = noteModel.Content; note.ModifiedUtc = DateTime.UtcNow; dbContext.SaveChanges(); return(DbMynaContext.GetUtcDateTime(note.ModifiedUtc).Value); } return(null); }
public NoteModel GetNote(IPwdManService pwdManService, string authenticationToken, long id) { logger.LogDebug("Get note for ID {id}...", id); var user = pwdManService.GetUserFromToken(authenticationToken); var dbContext = pwdManService.GetDbContext(); var note = dbContext.DbNotes.SingleOrDefault( (n) => n.Id == id && n.DbUserId == user.Id); if (note != null) { return(new NoteModel { Id = note.Id, LastModifiedUtc = DbMynaContext.GetUtcDateTime(note.ModifiedUtc).Value, Title = note.Title, Content = note.Content }); } return(null); }
public List <HighScore> GetHighScores() { var opt = GetOptions(); var ret = new List <HighScore>(); var del = new List <DbTetrisHighScore>(); var dbContext = GetDbContext(); var highScores = dbContext.DbTetrisHighScore.OrderByDescending(sc => sc.Score); foreach (var hs in highScores) { var highScore = new HighScore { Name = hs.Name, Created = DbMynaContext.GetUtcDateTime(hs.Created).Value, Level = hs.Level, Lines = hs.Lines, Score = hs.Score }; var diff = DateTime.UtcNow - highScore.Created; if (diff.TotalDays > opt.KeepHighscores) { del.Add(hs); continue; } ret.Add(highScore); if (ret.Count >= 10) { break; } } if (del.Any()) { dbContext.DbTetrisHighScore.RemoveRange(del); dbContext.SaveChanges(); } return(ret); }