public CommentDAL FindCommentByCommentID(int CommentID) { CommentDAL ProposedReturnValue = null; try { EnsureConnected(); using (SqlCommand command = new SqlCommand("FindCommentByCommentID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@CommentID", CommentID); using (SqlDataReader reader = command.ExecuteReader()) { CommentMapper mapper = new CommentMapper(reader); int count = 0; while (reader.Read()) { ProposedReturnValue = mapper.CommentFromReader(reader); count++; } if (count > 1) { throw new Exception($"Found more than 1 Comment with key {CommentID}"); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public List <CommentDAL> GetCommentsRelatedToUserID(int UserID, int skip, int take) { List <CommentDAL> ProposedReturnValue = new List <CommentDAL>(); try { EnsureConnected(); using (SqlCommand command = new SqlCommand("GetCommentsRelatedToUserID", _connection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@UserID", UserID); command.Parameters.AddWithValue("@Skip", skip); command.Parameters.AddWithValue("@Take", take); using (SqlDataReader reader = command.ExecuteReader()) { CommentMapper mapper = new CommentMapper(reader); while (reader.Read()) { CommentDAL comment = mapper.CommentFromReader(reader); ProposedReturnValue.Add(comment); } } } } catch (Exception ex) when(Log(ex)) { } return(ProposedReturnValue); }
public CommentBLL(DataAccessLayer.CommentDAL dal) { this.CommentID = dal.CommentID; this.GameComment = dal.GameComment; this.UserID = dal.UserID; this.GameID = dal.GameID; this.Liked = dal.Liked; this.GameName = dal.GameName; this.UserName = dal.UserName; }
public CommentDAL CommentFromReader(System.Data.SqlClient.SqlDataReader reader) { CommentDAL ProposedReturnValue = new CommentDAL(); ProposedReturnValue.CommentID = reader.GetInt32(OffsetToCommentID); ProposedReturnValue.GameComment = reader.GetString(OffsetToGameComment); ProposedReturnValue.UserID = reader.GetInt32(OffsetToUserID); ProposedReturnValue.GameID = reader.GetInt32(OffsetToGameID); ProposedReturnValue.Liked = reader.GetBoolean(OffsetToLiked); ProposedReturnValue.GameName = reader.GetString(OffsetToGameName); ProposedReturnValue.UserName = reader.GetString(OffsetToUserName); return(ProposedReturnValue); }