/// <summary> /// Adds the one song to table. /// </summary> /// <returns>Return the error code.</returns> /// <param name="song">Song.</param> public async Task <int> AddOneSongToTable(Song song) { int result = ErrorCodeModel.ErrorBecauseBugs; if (song == null) { // the data for updating is empty result = ErrorCodeModel.SongIsNull; return(result); } if (string.IsNullOrEmpty(song.SongNo)) { // the song no that input by user is empty result = ErrorCodeModel.SongNoIsEmpty; return(result); } Song oldSong = await FindOneSongBySongNo(song.SongNo); if (oldSong != null) { // song_no is duplicate result = ErrorCodeModel.SongNoDuplicate; return(result); } // verifying the validation for song data int validCode = await VerifySong(song); if (validCode != ErrorCodeModel.Succeeded) { // data is invalid result = validCode; return(result); } using (var dbTransaction = _context.Database.BeginTransaction()) { try { _context.Add(song); await _context.SaveChangesAsync(); dbTransaction.Commit(); result = ErrorCodeModel.Succeeded; } catch (DbUpdateException ex) { string errorMsg = ex.ToString(); Console.WriteLine("Failed to add one song: \n" + errorMsg); dbTransaction.Rollback(); result = ErrorCodeModel.DatabaseError; } } return(result); }
/// <summary> /// Adds the one singarea to table. /// </summary> /// <returns>Return the error code.</returns> /// <param name="singarea">Singarea.</param> public async Task <int> AddOneSingareaToTable(Singarea singarea) { int result = ErrorCodeModel.ErrorBecauseBugs; if (singarea == null) { // the data for updating is empty result = ErrorCodeModel.SingareaIsNull; return(result); } if (string.IsNullOrEmpty(singarea.AreaNo)) { // the singarea no that input by user is empty result = ErrorCodeModel.SingareaNoIsEmpty; return(result); } Singarea oldSingarea = await FindOneSingareaByAreaNo(singarea.AreaNo); if (oldSingarea != null) { // singarea no is duplicate result = ErrorCodeModel.SingareaNoDuplicate; return(result); } using (var dbTransaction = _context.Database.BeginTransaction()) { try { _context.Add(singarea); await _context.SaveChangesAsync(); dbTransaction.Commit(); result = ErrorCodeModel.Succeeded; } catch (DbUpdateException ex) { string errorMsg = ex.ToString(); Console.WriteLine("Failed to add one singarea: \n" + errorMsg); dbTransaction.Rollback(); result = ErrorCodeModel.DatabaseError; } } return(result); }
/// <summary> /// Adds the one language to table. /// </summary> /// <returns>Return the error code.</returns> /// <param name="language">Language.</param> public async Task <int> AddOneLanguageToTable(Language language) { int result = ErrorCodeModel.ErrorBecauseBugs; if (language == null) { // the data for updating is empty result = ErrorCodeModel.LanguageIsNull; return(result); } if (string.IsNullOrEmpty(language.LangNo)) { // the language no that input by user is empty result = ErrorCodeModel.LanguageNoIsEmpty; return(result); } Language oldLanguage = await FindOneLanguageByLangNo(language.LangNo); if (oldLanguage != null) { // language no is duplicate result = ErrorCodeModel.LanguageNoDuplicate; return(result); } using (var dbTransaction = _context.Database.BeginTransaction()) { try { _context.Add(language); await _context.SaveChangesAsync(); dbTransaction.Commit(); result = ErrorCodeModel.Succeeded; } catch (DbUpdateException ex) { string errorMsg = ex.ToString(); Console.WriteLine("Failed to add one language: \n" + errorMsg); dbTransaction.Rollback(); result = ErrorCodeModel.DatabaseError; } } return(result); }
/// <summary> /// Adds the one playerscore to table. /// </summary> /// <returns>Return the error code.</returns> /// <param name="playerscore">Playerscore.</param> public async Task <int> AddOnePlayerscoreToTable(Playerscore playerscore) { int result = ErrorCodeModel.ErrorBecauseBugs; if (playerscore == null) { // the data for updating is empty result = ErrorCodeModel.PlayerscoreIsNull; return(result); } if (string.IsNullOrEmpty(playerscore.PlayerName)) { // the playerscore no that input by user is empty result = ErrorCodeModel.PlayerNameIsEmpty; return(result); } using (var dbTransaction = _context.Database.BeginTransaction()) { try { _context.Add(playerscore); await _context.SaveChangesAsync(); dbTransaction.Commit(); result = ErrorCodeModel.Succeeded; } catch (DbUpdateException ex) { string errorMsg = ex.ToString(); Console.WriteLine("Failed to add one playerscore: \n" + errorMsg); dbTransaction.Rollback(); result = ErrorCodeModel.DatabaseError; } } return(result); }