public Result <PostComment> Insert(PostComment comment) { var result = new Result <PostComment>(); try { comment.ID = GetID(); string query = "BEGIN insertComment(" + comment.ID + ",'" + comment.COMMENTS + "'," + comment.POSTID + "," + comment.USERID + "); END;"; if (!ValidationHelper.IsStringValid(comment.COMMENTS)) { result.HasError = true; result.Message = "Invalid Comment"; return(result); } DataAccess.ExecuteQuery(query); result = GetByID(comment.ID); } catch (Exception ex) { result.HasError = true; result.Message = ex.Message; } return(result); }
private PostComment ConvertToEntity(DataRow row) { try { PostComment u = new PostComment(); u.ID = Int32.Parse(row["ID"].ToString()); u.POSTID = Int32.Parse(row["POSTID"].ToString()); u.USERID = Int32.Parse(row["USERID"].ToString()); u.COMMENTS = row["COMMENTS"].ToString(); u.UserEmail = row["EMAIL"].ToString(); u.COMMENTDATE = Convert.ToDateTime(row["COMMENTDATE"].ToString()); return(u); } catch (Exception) { return(null); } }
public List <PostComment> GetAll() { var result = new List <PostComment>(); try { string query = "select c.*,u.Email from PostComment c,UserInfo u where c.UserID=u.ID order by c.ID"; var dt = DataAccess.GetDataTable(query); if (dt != null && dt.Rows.Count != 0) { for (int i = 0; i < dt.Rows.Count; i++) { PostComment u = ConvertToEntity(dt.Rows[i]); result.Add(u); } } } catch (Exception ex) { } return(result); }
public Result <PostComment> Save(PostComment value) { throw new NotImplementedException(); }