예제 #1
0
        public void CreateTest()
        {
            String stalkId    = "4";
            int    talkId     = 20;
            int    UserInfoId = 5645;
            string msg        = String.Empty;

            if (String.IsNullOrEmpty(stalkId))
            {
                msg = "fail";
            }

            if (FavorsService.GetEntities(u => u.TalkID == talkId && u.UserInfoID == UserInfoId).Count() > 0)
            {
                msg = "fail";
            }
            Favors favors = new Favors()
            {
                UserInfoID = UserInfoId,
                TalkID     = talkId,
                CreateTime = DateTime.Now,
                ModfiedOn  = DateTime.Now,
                Status     = (short)Model.Enum.DelFlagEnum.Normal,
            };
            Talks talks = TalksService.GetEntities(u => u.TalkID == talkId).FirstOrDefault();

            talks.TalkFavorsNum = talks.TalkFavorsNum + 1;
            if (FavorsService.Add(favors) != null && TalksService.Update(talks))
            {
                msg = "success";
            }
            msg = "fail";
        }
예제 #2
0
        public ActionResult Create()
        {
            if (LoginUser == null)
            {
                return(Json(new { msg = "nologin" }, JsonRequestBehavior.AllowGet));
            }
            int talkId = 0;

            if (String.IsNullOrEmpty(Request["talkId"]))
            {
                return(Json(new { msg = "fail" }, JsonRequestBehavior.AllowGet));
            }
            talkId = int.Parse(Request["talkId"]);
            if (FavorsService.GetEntities(u => u.TalkID == talkId && u.UserInfoID == LoginUser.UserInfoID).Count() > 0)
            {
                return(Json(new { msg = "fail" }, JsonRequestBehavior.AllowGet));
            }
            Favors favors = new Favors()
            {
                UserInfoID = LoginUser.UserInfoID,
                TalkID     = talkId,
                CreateTime = DateTime.Now,
                ModfiedOn  = DateTime.Now,
                Status     = (short)Model.Enum.DelFlagEnum.Normal,
            };
            Talks talks = TalksService.GetEntities(u => u.TalkID == talkId).FirstOrDefault();

            talks.TalkFavorsNum = talks.TalkFavorsNum + 1;
            if (FavorsService.Add(favors) != null && TalksService.Update(talks))
            {
                return(Json(new { msg = "success" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { msg = "fail" }, JsonRequestBehavior.AllowGet));
        }