コード例 #1
0
        public bool SaveComment(long userId, string symbol, String comment)
        {
            try
            {
                using (var context = new EntityContext())
                {
                    var _comment = context.StockComment.SingleOrDefault(x => x.User_ID == userId && x.Stock == symbol);
                    if (_comment != null)
                    {
                        _comment.Comment = comment;
                    }
                    else
                    {
                        _comment = new StockComment
                        {
                            Comment = comment,
                            User_ID = userId,
                            Timestamp = DateTime.Now,
                            Stock = symbol
                        };
                        context.StockComment.Add(_comment);
                    }

                    context.SaveChanges();
                    return true;

                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
コード例 #2
0
 public bool SaveComment(StockComment comment)
 {
     try
     {
         using (var context = new EntityContext())
         {
             context.StockComment.Add(comment);
             context.SaveChanges();
             return true;
         }
     }
     catch (Exception ex)
     {
         return false;
     }
 }