예제 #1
0
        /// <summary>
        /// 记录下载数
        /// </summary>
        /// <param name="id">资源id</param>
        /// <param name="appId">附件id</param>
        /// <param name="db"></param>
        /// <returns></returns>
        public bool AddDownLoadNum(string id, string appId, string userId, JSZX_ResourceEntities db)
        {
            T_Res_Result result = null;

            try
            {
                //var query = from t in db.T_Res_Result
                //            where t.RES_ID == id && t.APPEND_ID == appId
                //            select t;
                //资源ID不作为条件检索数据,附件ID唯一,才是关键字
                var query = from t in db.T_Res_Result
                            where t.APPEND_ID == appId
                            select t;

                List <T_Res_Result> list = query.ToList();

                if (list == null || list.Count == 0)
                {
                    result              = new T_Res_Result();
                    result.ID           = Guid.NewGuid().ToString();
                    result.RES_ID       = id;
                    result.APPEND_ID    = appId;
                    result.DOWNLOAD_NUM = 1;
                    result.CREATEID     = userId;
                    result.CREATETIME   = DateTime.Now;

                    db.T_Res_Result.Add(result);
                    db.SaveChanges();
                }
                else
                {
                    //result = db.T_Res_Result.First(t => t.APPEND_ID == appId && t.RES_ID == id);
                    //资源ID不作为条件检索数据,附件ID唯一,才是关键字
                    result = db.T_Res_Result.First(t => t.APPEND_ID == appId);

                    int downloadNum = Convert.ToInt32(result.DOWNLOAD_NUM);
                    downloadNum = downloadNum + 1;

                    result.DOWNLOAD_NUM = downloadNum;
                    result.MODIFYID     = userId;
                    result.MODIFYTIME   = DateTime.Now;

                    db.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                clsLog.ErrorLog("Resource", "AddDownLoadNum", ex.Message);
                return(false);
            }
        }
예제 #2
0
        /// <summary>
        /// 记录评价数
        /// </summary>
        /// <param name="id">资源id</param>
        /// <param name="appId">附件id</param>
        /// <param name="db"></param>
        /// <returns></returns>
        public bool AddReviewNum(string id, string appId, double grade, string userId, JSZX_ResourceEntities db)
        {
            T_Res_Result result = null;

            try
            {
                var query = from t in db.T_Res_Result
                            where t.RES_ID == id && t.APPEND_ID == appId
                            select t;

                List <T_Res_Result> list = query.ToList();

                if (list == null || list.Count == 0)
                {
                    result            = new T_Res_Result();
                    result.ID         = Guid.NewGuid().ToString();
                    result.RES_ID     = id;
                    result.APPEND_ID  = appId;
                    result.REVIEW_NUM = 1;
                    result.CREATEID   = userId;
                    result.CREATETIME = DateTime.Now;

                    if (grade >= 4)
                    {
                        result.PRAISE_PRE = 1;
                    }
                    else
                    {
                        result.PRAISE_PRE = 0;
                    }

                    db.T_Res_Result.Add(result);
                    //db.SaveChanges();
                }
                else
                {
                    result = db.T_Res_Result.First(t => t.APPEND_ID == appId && t.RES_ID == id);

                    int reviewNum = 0;
                    if (result.REVIEW_NUM != null)
                    {
                        reviewNum = Convert.ToInt32(result.REVIEW_NUM);
                    }
                    reviewNum = reviewNum + 1;

                    int goodGrade = db.T_Res_Score.Count(t => t.RES_ID == id && t.APPEND_ID == appId && t.GRADE >= 4);
                    if (grade >= 4)
                    {
                        goodGrade = goodGrade + 1;
                    }

                    result.REVIEW_NUM = reviewNum;
                    result.PRAISE_PRE = Convert.ToDecimal(Math.Round(Convert.ToDouble(goodGrade) / Convert.ToDouble(reviewNum), 2));
                    result.MODIFYID   = userId;
                    result.MODIFYTIME = DateTime.Now;

                    //db.SaveChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                clsLog.ErrorLog("Resource", "AddReviewNum", ex.Message);
                return(false);
            }
        }