예제 #1
0
        protected async override Task <HandleResult> HandleCoreAsync(UnloveMottoRequest reqObj)
        {
            var lm = new LoveMotto {
                MID    = reqObj.MID,
                TheDay = reqObj.TheDay,
                UID    = reqObj.UserId,
            };

            var rowAffected = await _mottoRepo.RemoveLoveMottoAsync(lm);

            if (rowAffected > 0)
            {
                _eventPublisher.Publish <UnloveMottoEvent>(new UnloveMottoEvent
                {
                    LoveMotto = lm
                });

                return(new UnloveMottoResult
                {
                    State = HandleStates.Success,
                    Msg = "操作成功"
                });
            }

            return(new UnloveMottoResult
            {
                State = HandleStates.NoDataFound,
                Msg = "偶得不存在或已被删除"
            });
        }
예제 #2
0
        public async Task <int> AddLoveMottoAsync(LoveMotto lm)
        {
            int rowAffected = 0;

            using (var conn = _connProvider.GetConnection())
            {
                var tran = conn.BeginTransaction();
                try
                {
                    rowAffected = await conn.ExecuteAsync("insert into LoveMottos (UID,MID,TheDay, LoveTime) values(@UID,@MID,@TheDay, @LoveTime)",
                                                          lm, tran);

                    if (rowAffected > 0)
                    {
                        await conn.ExecuteAsync("update Mottos set loves=Loves+1 where id=@MID",
                                                new
                        {
                            MID = lm.MID
                        },
                                                tran);


                        await conn.ExecuteAsync("update UserStatistics set LovedMottos=LovedMottos+1 where uid=@UID",
                                                new
                        {
                            UID = lm.UID
                        },
                                                tran);

                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                catch
                {
                    try
                    {
                        tran.Rollback();
                    }
                    catch {
                    }

                    throw;
                }
            }


            return(rowAffected);
        }
예제 #3
0
        public async Task <int> RemoveLoveMottoAsync(LoveMotto lm)
        {
            int rowAffected = 0;

            using (var conn = _connProvider.GetConnection())
            {
                var tran = conn.BeginTransaction();
                try
                {
                    rowAffected = await conn.ExecuteAsync("delete from LoveMottos where UID=@UID and MID=@MID",
                                                          lm, tran);

                    if (rowAffected > 0)
                    {
                        await conn.ExecuteAsync("update Mottos set Loves=Loves-1 where Id=@MID",
                                                new
                        {
                            MID = lm.MID
                        }, tran);

                        await conn.ExecuteAsync("update UserStatistics set LovedMottos=LovedMottos-1 where UID=@UID",
                                                new {
                            UID = lm.UID
                        },
                                                tran);

                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                catch
                {
                    try
                    {
                        tran.Rollback();
                    }
                    catch
                    {
                    }

                    throw;
                }
            }


            return(rowAffected);
        }
예제 #4
0
        protected async override Task <HandleResult> HandleCoreAsync(LoveMottoRequest reqObj)
        {
            if (_cacheManager.GetCache <IUserInfoCache>().HasLovedMotto(reqObj.UserId, reqObj.MID))
            {
                return(new LoveMottoResult
                {
                    State = HandleStates.Success,
                    Msg = "操作成功"
                });
            }

            var lm = new LoveMotto
            {
                MID      = reqObj.MID,
                UID      = reqObj.UserId,
                TheDay   = reqObj.TheDay,
                LoveTime = DateTime.Now
            };

            var rowAffected = await _mottoRepo.AddLoveMottoAsync(lm);

            if (rowAffected > 0)
            {
                _eventPublisher.Publish <LoveMottoEvent>(new LoveMottoEvent
                {
                    LoveMotto = lm
                });

                return(new LoveMottoResult
                {
                    State = HandleStates.Success,
                    Msg = "操作成功"
                });
            }

            return(new LoveMottoResult
            {
                State = HandleStates.NoDataFound,
                Msg = "偶得不存在或已被删除"
            });
        }