public List<AuthorDTO> GetAllAuthor() { List<AuthorDTO> list = new List<AuthorDTO>(); try { SqlDataReader reader = ConnectionManager.GetCommand("SP0301ALL", new Dictionary<string, SqlDbType>() { }, new List<object>() { }).ExecuteReader(); while (reader.Read()) { AuthorDTO authorDTO = new AuthorDTO(); authorDTO.AuthorId = int.Parse(reader["AuthorID"].ToString()); authorDTO.AuthorName = reader["AuthorName"].ToString(); authorDTO.CreatedDate = (DateTime)reader["CreatedDate"]; authorDTO.UpdatedDate = (DateTime)reader["UpdatedDate"]; list.Add(authorDTO); } reader.Close(); } catch (Exception e) { Log.Error("Error at AuthorDAO - GetAllAuthor", e); return null; } return list; }
public List<AuthorOfBookDTO> GetAuthorListByIsbn(String isbn) { List<AuthorOfBookDTO> list = new List<AuthorOfBookDTO>(); try { SqlDataReader reader = ConnectionManager.GetCommand("SP0801ISBN", new Dictionary<string, SqlDbType>() { { "@Param1", SqlDbType.NVarChar } }, new List<object>() { isbn }).ExecuteReader(); while (reader.Read()) { AuthorOfBookDTO authorOfBookDto = new AuthorOfBookDTO(); authorOfBookDto.ISBN = reader["ISBN"].ToString(); //Add code AuthorDTO authorDto = new AuthorDTO(); authorDto.AuthorId = int.Parse(reader["AuthorID"].ToString()); authorOfBookDto.Author = authorDto; authorOfBookDto.CreatedDate = (DateTime)reader["CreatedDate"]; authorOfBookDto.UpdatedDate = (DateTime)reader["UpdatedDate"]; list.Add(authorOfBookDto); } reader.Close(); } catch (Exception e) { Log.Error("Error at AuthorOfBookDAO - GetAuthorListByISBN", e); return null; } return list; }
public int InsertAuthor(AuthorDTO author) { int rs = 0; using (SqlTransaction trans = ConnectionManager.Con.BeginTransaction()) { AuthorDAO dao = new AuthorDAO(); rs = dao.InsertAuthor(author); if (rs == 1) { trans.Commit(); } else { trans.Rollback(); } } return rs; }
public int DeleteAuthor(AuthorDTO author) { try { ConnectionManager.GetCommand("SP0304", new Dictionary<string, SqlDbType>() { {"@Param1", SqlDbType.Int} }, new List<object>() { author.AuthorId }).ExecuteNonQuery(); } catch (Exception e) { Log.Error("Error at AuthorDAO - DeleteAuthor", e); return 0; } return 1; }
/// <summary> /// Get Author from Database by specific Id /// </summary> /// <param name="authorId"></param> /// <returns></returns> public AuthorDTO GetAuthorById(int authorId) { // 20120306 QUANLM ++ AuthorDTO authorDTO = null; try { SqlDataReader reader = ConnectionManager.GetCommand("SP0301AI", new Dictionary<string, SqlDbType>() { { "@Param1", SqlDbType.Int } }, new List<object>() { authorId }).ExecuteReader(); if (reader.Read()) { authorDTO = new AuthorDTO(); authorDTO.AuthorId = int.Parse(reader["AuthorID"].ToString()); authorDTO.AuthorName = reader["AuthorName"].ToString(); authorDTO.CreatedDate = (DateTime)reader["CreatedDate"]; authorDTO.UpdatedDate = (DateTime)reader["UpdatedDate"]; } reader.Close(); } catch (Exception e) { Log.Error("Error at AuthorDAO - GetAuthorByID", e); return null; } return authorDTO; // 20120306 QUANLM -- }
public int UpdateAuthor(AuthorDTO author) { author.UpdatedDate = DateTime.Now; try { ConnectionManager.GetCommand("SP0303", new Dictionary<string, SqlDbType>() { {"@Param1", SqlDbType.Int}, {"@Param2", SqlDbType.NVarChar}, {"@Param3", SqlDbType.DateTime}, {"@Param4", SqlDbType.DateTime} }, new List<object>() { author.AuthorId, author.AuthorName, author.CreatedDate, author.UpdatedDate }).ExecuteNonQuery(); } catch (Exception e) { Log.Error("Error at AuthorDAO - UpdateAuthor", e); return 0; } return 1; }