public CommentInfo AddComment(long postId, CommentInfo info, bool isWeb) { try { CommentManager mgr = new CommentManager(); TokenInfo tokenInfo = new HelperMethods().GetUserToken<TokenInfo>(isWeb, HttpContext.Current); info.PostId = postId; info.UserIdf = tokenInfo.Idf; return mgr.AddComment(info, tokenInfo.TerritoryId); } catch (Exception ex) { throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError); } }
public CommentInfo AddComment(CommentInfo info, int territoryId) { try { if (!string.IsNullOrWhiteSpace(info.Comment)) { using (SqlDataAdapter adapter = new SqlDataAdapter("[posts].[AddComment]", AppConfigManager.ConnectionString)) { adapter.SelectCommand.CommandType = CommandType.StoredProcedure; adapter.SelectCommand.Parameters.AddWithValue("@PostId", info.PostId); adapter.SelectCommand.Parameters.AddWithValue("@UserIdf", info.UserIdf); adapter.SelectCommand.Parameters.AddWithValue("@TerritoryId", territoryId); adapter.SelectCommand.Parameters.AddWithValue("@Comment", info.Comment); DataTable dt = new DataTable(); adapter.Fill(dt); return (from row in dt.AsEnumerable() select new CommentInfo { Id = Convert.ToInt64(row["Id"]), PostId = Convert.ToInt64(row["PostId"]), UserIdf = Guid.Parse(Convert.ToString(row["UserIdf"])), CreatedOn = Convert.ToDateTime(row["CreatedOn"]), ModifiedOn = Convert.ToDateTime(row["CreatedOn"]), }).FirstOrDefault(); } } throw new Exception(CodeHelper.UnableToEditComment); } catch (Exception ex) { string msg = ex.Message; throw new Exception(CodeHelper.UnableToComment); } }
public bool EditComment(CommentInfo info) { try { if (!string.IsNullOrWhiteSpace(info.Comment)) { using (SqlDataAdapter adapter = new SqlDataAdapter("[posts].[EditComment]", AppConfigManager.ConnectionString)) { adapter.SelectCommand.CommandType = CommandType.StoredProcedure; adapter.SelectCommand.Parameters.AddWithValue("@Id", info.Id); adapter.SelectCommand.Parameters.AddWithValue("@PostId", info.PostId); adapter.SelectCommand.Parameters.AddWithValue("@UserIdf", info.UserIdf); adapter.SelectCommand.Parameters.AddWithValue("@Comment", info.Comment); adapter.SelectCommand.Connection.Open(); int results = adapter.SelectCommand.ExecuteNonQuery(); adapter.SelectCommand.Connection.Close(); if (results > 0) return true; } } throw new Exception(CodeHelper.UnableToEditComment); } catch (Exception ex) { string msg = ex.Message; throw new Exception(CodeHelper.UnableToEditComment); } }
public bool DeleteComment(long postId, CommentInfo info, bool isWeb) { try { CommentManager mgr = new CommentManager(); Guid userIdf = new HelperMethods().GetUserIdf(isWeb, HttpContext.Current); info.PostId = postId; info.UserIdf = userIdf; return mgr.DeleteComment(info); } catch (Exception ex) { throw new WebFaultException<string>(ex.Message, System.Net.HttpStatusCode.InternalServerError); } }