Пример #1
0
        /// <summary>
        /// This function adds a review of an article after being analyzed. It returns
        /// true if it was successful.
        /// </summary>
        /// <param name="user_id">User id of user who analyzed the article</param>
        /// <param name="stock_id">Stock id of the stock that was associated with the article</param>
        /// <param name="article_id">Article id of the article that was reviewed</param>
        /// <param name="score">Score of the article after being rated in analysis phase</param>
        /// <returns>returns true if analysis was sucessfully added to the database</returns>
        public bool addAnalysis(int user_id, int stock_id, int article_id, int score)
        {
            bool success = false;

            using (var db = new stock_advisorDataContext(Program.ConnectionString))
            {
                REVIEW search = (from p in db.REVIEWs
                                 where p.Article_id == article_id &&
                                 p.User_id == user_id &&
                                 p.Stock_id == stock_id
                                 select p).FirstOrDefault();

                if (search == null)                 //record doesn't exist
                {
                    //create user_info object w/params
                    var newEntry = new REVIEW()
                    {
                        User_id    = user_id,
                        Stock_id   = stock_id,
                        Article_id = article_id,
                        Score      = score
                    };

                    db.REVIEWs.InsertOnSubmit(newEntry);

                    try
                    {
                        db.SubmitChanges();                         //execute insert
                        //verify that was successfully inserted
                        var added = db.REVIEWs.SingleOrDefault(a => a.Stock_id == stock_id && a.User_id == user_id && a.Article_id == article_id);
                        if (added != null)
                        {
                            success = true;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Exception caught during review insert:\n");
                        Console.WriteLine(e.Message);
                    }
                }
                else                    //record exists already
                {
                    success = false;
                }
            }
            return(success);
        }
 private void attach_REVIEWs(REVIEW entity)
 {
     this.SendPropertyChanging();
     entity.USER_INFO = this;
 }
 private void detach_REVIEWs(REVIEW entity)
 {
     this.SendPropertyChanging();
     entity.USER_INFO = null;
 }
 partial void DeleteREVIEW(REVIEW instance);
 partial void UpdateREVIEW(REVIEW instance);
 partial void InsertREVIEW(REVIEW instance);
 private void detach_REVIEWs(REVIEW entity)
 {
     this.SendPropertyChanging();
     entity.ARTICLE = null;
 }
 private void attach_REVIEWs(REVIEW entity)
 {
     this.SendPropertyChanging();
     entity.ARTICLE = this;
 }