Exemplo n.º 1
0
        protected async override Task <HandleResult> HandleCoreAsync(DelCollectionMottoRequest reqObj)
        {
            var tm = new CollectionMotto {
                CID = reqObj.CID,
                MID = reqObj.MID
            };

            var rowAffected = await _collectionRepo.RemoveCollectionMottoAsync(tm);

            if (rowAffected > 0)
            {
                _eventPublisher.Publish(new UnCollectMottoEvent
                {
                    UID             = reqObj.UserId,
                    CollectionMotto = tm
                });

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

            return(new DelCollectionMottoResult {
                State = HandleStates.NoDataFound,
                Msg = "未收录或不存在此偶得"
            });
        }
Exemplo n.º 2
0
        protected async override Task <HandleResult> HandleCoreAsync(AddCollectionMottoRequest reqObj)
        {
            var tm = new CollectionMotto {
                CID     = reqObj.CID,
                MID     = reqObj.MID,
                AddTime = DateTime.Now
            };

            var rowAffected = await _collectionRepo.AddCollectionMottoAsync(tm);

            if (rowAffected > 0)
            {
                _eventPublisher.Publish(new CollectMottoEvent
                {
                    UID             = reqObj.UserId,
                    CollectionMotto = tm
                });


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

            return(new AddCollectionMottoResult {
                State = HandleStates.UnkownError,
                Msg = "未知错误"
            });
        }
Exemplo n.º 3
0
        public async Task <int> RemoveCollectionMottoAsync(CollectionMotto tm)
        {
            var rowAffected = 0;

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

                    if (rowAffected > 0)
                    {
                        await conn.ExecuteAsync("update Collections set Mottos = Mottos-1 where ID=@CID",
                                                new
                        {
                            CID = tm.CID
                        }, tran);

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

            return(rowAffected);
        }
Exemplo n.º 4
0
        public async Task <int> AddCollectionMottoAsync(CollectionMotto tm)
        {
            int rowAffeted = 0;

            using (var conn = _connProvider.GetConnection())
            {
                var tran = conn.BeginTransaction();
                try
                {
                    rowAffeted = await conn.ExecuteAsync("insert into CollectionMottos (CID,MID,AddTime) values (@CID,@MID,@AddTime)",
                                                         tm, tran);

                    if (rowAffeted > 0)
                    {
                        await conn.ExecuteAsync("update Collections set Mottos = Mottos+1 where ID=@CID",
                                                new
                        {
                            CID = tm.CID
                        }, tran);

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

            return(rowAffeted);
        }