public void Delete(TbLike like) { SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "delete from TbLike where UserId=@UserId and MessageId=@MessageId"; cmd.Parameters.AddWithValue("@MessageId", like.MessageId); cmd.Parameters.AddWithValue("@UserId", like.UserId); cmd.ExecuteNonQuery(); }
public void Create(TbLike like) { SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "Insert Into TbLike (UserId,MessageId,Rank) values (@UserId,@MessageId,@Rank)"; cmd.Parameters.AddWithValue("@MessageId", like.MessageId); cmd.Parameters.AddWithValue("@UserId", like.UserId); cmd.Parameters.AddWithValue("@Rank", like.Rank); cmd.ExecuteNonQuery(); }
public static TbLike ToEntity(System.Data.IDataReader reader) { TbLike lik = null; lik = new TbLike(); lik.Id = Convert.ToInt32(reader["Id"]); lik.UserId = Convert.ToInt32(reader["UserId"]); lik.MessageId = Convert.ToInt32(reader["MessageId"]); lik.Rank = Convert.ToInt32(reader["Rank"]); return lik; }
public MethodResult LikeMessage(int userId, int messageId) { try { TbLike like = new TbLike(); like.UserId = userId; like.MessageId = messageId; like.Rank = 1; bool data = Business.Like.Create(like); return new MethodResult(false, null, data); } catch (HabbeException e) { return new MethodResult(true, e.Message, null); } }
public static bool Create(TbLike like) { using (DataAccess.Like db = new DataAccess.Like()) { TbLike duplike = db.Retrieve(like.MessageId, like.UserId); if (duplike == null) { db.Create(like); return true; } else { db.Delete(like); return false; } } }