public static bool Register(string username, string password) { using (var db = new NotesModel()) { var isExist = db.User.Any(x => x.Username == username); if (!isExist) { var user = new User(); user.Username = username; var hashedPassword = CryptoUtil.HashPassword(password); user.Password = hashedPassword; user.Role = "User"; db.User.Add(user); db.SaveChanges(); return(true); } return(false); } }
public bool AddNote([FromBody] string pNote) { using (var db = new NotesModel()) { // Get user information according to token var username = User?.Identity?.Name; // if (!string.IsNullOrWhiteSpace(username)) { var note = new Note(); note.NoteText = pNote; note.Username = username; db.Note.Add(note); db.SaveChanges(); return(true); } } return(false); }