public bool InsertFeedback(Feedback feedback) { bool success = false; SqlCommand cmd = null; try { using (var connection = new SqlConnection(ConnectionString)) { cmd = new SqlCommand(); cmd.CommandText = @"INSERT INTO [dbo].[Feedback] ([Type] ,[Url]) VALUES (@Type, @Url)"; cmd.CommandType = CommandType.Text; cmd.Connection = connection; cmd.Parameters.AddWithValue("@Type", feedback.Type); cmd.Parameters.AddWithValue("@Url", feedback.Url); cmd.Connection.Open(); cmd.ExecuteNonQuery(); } success = true; } catch { throw; } finally { cmd.Connection.Close(); } return success; }
public bool Add(Feedback feedback) { if (feedback.Description.Length > 200) feedback.Description = feedback.Description.Substring(0, 196) + " ..."; return commentDac.InsertComment(feedback); }
public string AddComment(string content, string url, int parentId) { string result = string.Empty; try { var commentMgr = new CommentMgr(); var feedback = new Feedback(); feedback.FullText = content; feedback.Description = content; feedback.Url = url; feedback.Type = "COMMENT"; feedback.ParentId = parentId; commentMgr.Add(feedback); return result; } catch (Exception ex) { throw ex; } }
public string AddFeedback(string url, string type) { string result = string.Empty; try { var commentMgr = new CommentMgr(); var feedback = new Feedback(); feedback.Url = url; feedback.Type = type; commentMgr.AddFeedback(feedback); result = JsonConvert.SerializeObject(feedback); } catch { } return result; }
public bool InsertComment(Feedback feedback) { bool success = false; SqlCommand cmd = null; try { using (var connection = new SqlConnection(ConnectionString)) { cmd = new SqlCommand(); cmd.CommandText = @"INSERT INTO [dbo].[Feedback] ([FullText], [Description], [Url], Type, parentId) VALUES (@FullText, @Description, @Url, @Type, @ParentId)"; cmd.CommandType = CommandType.Text; cmd.Connection = connection; cmd.Parameters.AddWithValue("@FullText", feedback.FullText); cmd.Parameters.AddWithValue("@Description", feedback.Description); cmd.Parameters.AddWithValue("@Url", feedback.Url); cmd.Parameters.AddWithValue("@Type", feedback.Type); cmd.Parameters.AddWithValue("@ParentId", feedback.ParentId); cmd.Connection.Open(); cmd.ExecuteNonQuery(); } success = true; } catch { throw; } finally { cmd.Connection.Close(); } return success; }
public List<Feedback> GetByUrl(Feedback feedback) { return commentDac.SelectByUrl(feedback); }
public bool AddFeedback(Feedback feedback) { return commentDac.InsertFeedback(feedback); }
public List<Feedback> SelectByUrl(Feedback comment) { var listOfComment = new List<Feedback>(); SqlCommand cmd = null; try { using (var connection = new SqlConnection(ConnectionString)) { cmd = new SqlCommand(); cmd.CommandText = @"SELECT Id, Description, CreatedDate, ParentId FROM [Feedback] WHERE URL = @Url AND TYPE = 'COMMENT'"; cmd.CommandType = CommandType.Text; cmd.Connection = connection; cmd.Parameters.AddWithValue("@Url", comment.Url); cmd.Connection.Open(); dr = cmd.ExecuteReader(); while (this.dr.Read()) { var comm = new Feedback(); comm.Id = Convert.ToInt32(dr["Id"]); comm.Description = dr["Description"].ToString(); comm.TimeCreated = Convert.ToDateTime(dr["CreatedDate"]); comm.ParentId = Convert.ToInt32(dr["ParentId"]); listOfComment.Add(comm); } } } catch { throw; } finally { if (this.dr != null) { this.dr.Close(); } cmd.Connection.Close(); } return listOfComment; }
public string GetCommentByUrl(string url) { string result = string.Empty; try { var commentMgr = new CommentMgr(); var feedback = new Feedback(); feedback.Url = url; var listOfComment = commentMgr.GetByUrl(feedback); JsonSerializer _jsonWriter = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore }; result = JsonConvert.SerializeObject(listOfComment, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); return result; } catch (Exception ex) { throw ex; } }