Пример #1
0
 public DataSet getComments(Comments commentObj, string connectionString)
 {
     SqlParameter pCommentId = new SqlParameter("@CommentId", SqlDbType.Int, 0);
     pCommentId.Value = commentObj.CommentId;
     SqlCommand cmd = new SqlCommand();
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.CommandText = "usp_GetCommentInfo";
     cmd.Parameters.Add(pCommentId);
     DataSet ds = new DataSet();
     DataLayer dataLayerObj = new DataLayer();
     ds = dataLayerObj.GetQuery(cmd, connectionString);
     return ds;
 }
Пример #2
0
 public void UpdateComment(Comments commentObj, string connectionString)
 {
     SqlParameter pCommentId = new SqlParameter("@CommentId", SqlDbType.Int, 0);
     SqlParameter pCommentField = new SqlParameter("@CommentsField", SqlDbType.NVarChar, 100);
     pCommentId.Value = commentObj.CommentId;
     pCommentField.Value = commentObj.CommentsField;
     SqlCommand cmd = new SqlCommand();
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.CommandText = "usp_UpdateUserSubmittedComment";
     cmd.Parameters.Add(pCommentId);
     cmd.Parameters.Add(pCommentField);
     DataLayer dataLayerObj = new DataLayer();
     cmd = dataLayerObj.Update(cmd, connectionString);
 }
Пример #3
0
        public DataSet SelectComment(Comments commentObj, string connString)
        {
            DataSet dsComment = new DataSet();
            SqlParameter pAdviceId = new SqlParameter("@AdviceId", SqlDbType.Int, 0);
            pAdviceId.Value = commentObj.AdviceId;

            SqlCommand cmdSQL = new SqlCommand();
            cmdSQL.CommandType = CommandType.StoredProcedure;
            cmdSQL.CommandText = "usp_GetCommentDetails";
            cmdSQL.Parameters.Add(pAdviceId);
            DataLayer datalayerObj = new DataLayer();
            dsComment = datalayerObj.GetQuery(cmdSQL, connString);
            return dsComment;
        }
Пример #4
0
 public bool IsValidComment(Comments commentObj, out string message)
 {
     bool isValidComment = true;
     StringBuilder builderMessage = new StringBuilder();
     string errorMessage = string.Empty;
     if (string.IsNullOrEmpty(commentObj.CommentsField))
     {
         isValidComment = false;
         errorMessage = "A blank comment cannot be submited.Please enter something";
         builderMessage.Append(errorMessage);
     }
     else if (commentObj.CommentsField.Length > 400)
     {
         isValidComment = false;
         errorMessage = "Comment should not exceed 100 words (400 chars)";
         builderMessage.Append(errorMessage);
     }
     message = builderMessage.ToString();
     return isValidComment;
 }
Пример #5
0
        public void InsertComment(Comments commentObj, string connString)
        {
            string errormsg;
            try
            {
                if (IsValidComment(commentObj, out errormsg))
                {
                    SqlParameter pAdviceId = new SqlParameter("@AdviceId", SqlDbType.Int, 0);
                    SqlParameter pUsername = new SqlParameter("@Username", SqlDbType.NVarChar, 50);
                    SqlParameter pCommentsField = new SqlParameter("@CommentsField", SqlDbType.NVarChar, 400);
                    SqlParameter pCommentDateTime = new SqlParameter("CommentDateTime", SqlDbType.DateTime, 0);

                    pAdviceId.Value = commentObj.AdviceId;
                    pUsername.Value = commentObj.Username;
                    pCommentsField.Value = commentObj.CommentsField;
                    pCommentDateTime.Value = commentObj.CommentDateTime;

                    SqlCommand cmdSql = new SqlCommand();
                    cmdSql.CommandType = CommandType.StoredProcedure;
                    cmdSql.CommandText = "usp_InsertComment";
                    cmdSql.Parameters.Add(pAdviceId);
                    cmdSql.Parameters.Add(pUsername);
                    cmdSql.Parameters.Add(pCommentsField);
                    cmdSql.Parameters.Add(pCommentDateTime);

                    DataLayer datalayerObj = new DataLayer();
                    cmdSql = datalayerObj.Insert(cmdSql, connString);
                }
                else
                {
                    throw new Exception(errormsg);
                }
            }
            catch
            {
                throw;
            }
        }