예제 #1
0
        public HttpResponseMessage SendPraise(int TalkId, int UserId)
        {
            Talk         talk         = db.Talks.FirstOrDefault(s => s.Id == TalkId);
            PraiseRecord praiseRecord = db.PraiseRecords.FirstOrDefault(s => s.UserId == UserId);

            if (praiseRecord == null)
            {
                try
                {
                    talk.Praise++;
                    PraiseRecord record = new PraiseRecord
                    {
                        UserId = UserId,
                    };
                    record.Count++;
                    db.PraiseRecords.Add(record);
                    db.Entry(talk).State = EntityState.Modified;
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    db.Entry(talk).State = EntityState.Unchanged;
                    return(ApiResponse.BadRequest(Message.EditFailure));
                }
                return(ApiResponse.Ok(Message.EditSuccess));
            }
            return(ApiResponse.Invalid("TalkId", "您已点过赞!"));
        }
예제 #2
0
        /// <summary>
        /// 添加点赞记录
        /// </summary>
        /// <param name="productid"></param>
        /// <returns></returns>
        public string Praise(int productid)
        {
            try
            {
                //判断是否登录
                if (User_Shop.IsLogin() == false)
                {
                    throw new Exception("请登陆后点赞");
                }
                string curUserID = User_Shop.GetMemberID();
                //判断是否赞过
                if (DB.PraiseRecord.Any(q => q.ProductID == productid && q.MemberID == curUserID))
                {
                    throw new Exception("亲,当前商品已经赞过了");
                }

                PraiseRecord record = new PraiseRecord();
                record.ProductID  = productid;
                record.MemberID   = curUserID;
                record.CreateTime = DateTime.Now;
                DB.PraiseRecord.Insert(record);

                //累计点赞数
                ShopProduct product = DB.ShopProduct.FindEntity(productid);
                product.PraiseCount++;
                DB.ShopProduct.Update(product);

                return("1");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
예제 #3
0
        /// <summary>
        /// 用户赞贴、收藏
        /// </summary>
        /// <returns></returns>
        public ActionResult PraiseCollect()
        {
            var key    = Request["key"].ToInt();
            var postid = Request["postid"].ToInt();
            var userid = Request["userid"].ToInt();

            using (var db = new ClubEntitie())
            {
                if (key == 1)
                {
                    var praiserecord = new PraiseRecord();
                    praiserecord.Postid     = postid;
                    praiserecord.Userid     = userid;
                    praiserecord.CreateTime = DateTime.Now;
                    db.PraiseRecord.Add(praiserecord);
                    db.SaveChanges();
                }
                else
                {
                    var collection = new Collection();
                    collection.Postid     = postid;
                    collection.Userid     = userid;
                    collection.CreateTime = DateTime.Now;
                    db.Collection.Add(collection);
                    db.SaveChanges();
                }
                //查询赞帖子的用户
                var praiserecords = db.PraiseRecord.OrderByDescending(a => a.id).Include(a => a.User).Where(a => a.Postid == postid).ToList();
                ViewBag.praiserecord = praiserecords;
                var listpraiserecord = new List <PraiserecordModel>();
                foreach (var item in praiserecords)
                {
                    var praiserecordmodel = new PraiserecordModel();
                    praiserecordmodel.postid    = item.Postid;
                    praiserecordmodel.userid    = item.Userid;
                    praiserecordmodel.username  = item.User.Name;
                    praiserecordmodel.userimage = item.User.Image;
                    praiserecordmodel.time      = item.CreateTime;
                    listpraiserecord.Add(praiserecordmodel);
                }
                if (Request.IsAjaxRequest())
                {
                    return(PartialView("_PraiseRecord", listpraiserecord));
                }
            }
            return(RedirectToAction("Browse"));
        }