Пример #1
0
        private void MaisuSum()
        {
            label10.Text = GetMaisuTotal().ToString("#,##0");
            int Zan;

            Zan         = Int32.Parse(label8.Text, System.Globalization.NumberStyles.Any) - Int32.Parse(label10.Text, System.Globalization.NumberStyles.Any);
            label7.Text = Zan.ToString("#,##0");

            if (Zan < 0)
            {
                label7.ForeColor = Color.Red;
                MessageBox.Show("ポスティングエリア枚数が配布枚数を超えています", MESSAGE_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                label7.ForeColor = Color.Black;
            }
        }
Пример #2
0
        /// <summary>
        /// 当前用户对帖子点赞
        /// </summary>
        public async Task ZanPostAsync(Guid postId)
        {
            Guid?    personId  = httpContextAccessor.HttpContext.User.GetUserId();
            string   sessionId = httpContextAccessor.HttpContext.Session.Id;
            Zan      zan       = null;
            DateTime now       = DateTime.Now;

            using (var work = this.dbFactory.StartWork())
            {
                Post post = await work.Post.SingleByIdAsync(postId);

                if (post == null || post.PostStatus != Enums.PostStatus.Publish)
                {
                    throw new Exception("该帖子不存在或已被删除");
                }
                // 如果是匿名用户
                if (personId == null)
                {
                    if (!(await work.Zan.IsZanAsync(sessionId, postId, Enums.ZanType.Post)))
                    {
                        //添加赞记录
                        zan = new Zan
                        {
                            Id        = GuidHelper.CreateSequential(),
                            SessionId = this.httpContextAccessor.HttpContext.Session.Id,
                            CommentId = null,
                            DoTime    = now,
                            PersonId  = null,
                            PostId    = postId,
                            ZanType   = Enums.ZanType.Post
                        };
                    }
                }
                else
                {
                    // 如果是登录用户
                    if (!(await work.Zan.IsZanAsync(personId.Value, postId, Enums.ZanType.Post)))
                    {
                        zan = new Zan
                        {
                            Id        = GuidHelper.CreateSequential(),
                            SessionId = this.httpContextAccessor.HttpContext.Session.Id,
                            CommentId = null,
                            DoTime    = now,
                            PersonId  = personId.Value,
                            PostId    = postId,
                            ZanType   = Enums.ZanType.Post
                        };
                    }
                }
                if (zan != null)
                {
                    using (var trans = work.BeginTransaction())
                    {
                        try
                        {
                            await work.Zan.InsertAsync(zan, trans);

                            // 累计帖子赞
                            await work.Connection.IncreaseAsync(nameof(Post), nameof(Post.LikeNum), nameof(Post.Id), postId, trans);

                            // 累计作者赞
                            await work.Connection.IncreaseAsync(nameof(PersonData), nameof(PersonData.LikeNum), nameof(PersonData.PersonId), post.PersonId, trans);

                            trans.Commit();
                        }
                        catch (Exception)
                        {
                            trans.Rollback();
                            throw;
                        }
                    }
                }
            }
        }