Exemplo n.º 1
0
        protected async override Task <HandleResult> HandleCoreAsync(LoveCollectionRequest reqObj)
        {
            var lt = new LoveCollection {
                UID             = reqObj.UserId,
                LoveTime        = DateTime.Now,
                CID             = reqObj.CID,
                CollectionTitle = ""
            };

            var rowAffected = await _collectionRepo.AddLoveCollectionAsync(lt);

            if (rowAffected > 0)
            {
                _eventPublisher.Publish <LoveCollectionEvent>(new LoveCollectionEvent {
                    LoveCollection = lt
                });

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

            return(new LoveCollectionResult
            {
                State = HandleStates.NoDataFound,
                Msg = "珍藏不存在"
            });
        }
Exemplo n.º 2
0
        protected async override Task <HandleResult> HandleCoreAsync(UnloveCollectionRequest reqObj)
        {
            var lt = new LoveCollection {
                CID = reqObj.CID,
                UID = reqObj.UserId
            };

            var rowAffected = await _collectionRepo.RemoveLoveCollectionAsync(lt);

            if (rowAffected > 0)
            {
                _eventPublisher.Publish(new UnLoveCollectionEvent
                {
                    LoveCollection = lt
                });

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

            return(new UnloveCollectionResult {
                State = HandleStates.NoDataFound,
                Msg = "珍藏不存在或已被删除"
            });
        }
Exemplo n.º 3
0
        public async Task <int> AddLoveCollectionAsync(LoveCollection lt)
        {
            int rowAffected = 0;

            using (var conn = _connProvider.GetConnection())
            {
                var tran = conn.BeginTransaction();

                try
                {
                    rowAffected = await conn.ExecuteAsync("insert into LoveCollections (UID,LoveTime,CID) values (@UID,@LoveTime,@CID)",
                                                          lt, tran);

                    if (rowAffected > 0)
                    {
                        await conn.ExecuteAsync("update UserStatistics set LovedCollections=LovedCollections+1 where UID=@uid",
                                                new
                        {
                            UID = lt.UID
                        }, tran);

                        await conn.ExecuteAsync("update Collections set Loves=Loves+1 where ID=@CID",
                                                new
                        {
                            CID = lt.CID
                        }, tran);

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

                    throw;
                }
            }

            return(rowAffected);
        }
Exemplo n.º 4
0
        public async Task <int> RemoveLoveCollectionAsync(LoveCollection lt)
        {
            int rowAffected = 0;

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

                    if (rowAffected > 0)
                    {
                        await conn.ExecuteAsync("update UserStatistics set LovedCollections=LovedCollections-1 where UID=@UID",
                                                new {
                            UID = lt.UID
                        }, tran);

                        await conn.ExecuteAsync("update Collections set Loves=Loves-1 where ID=@CID",
                                                new {
                            CID = lt.CID
                        }, tran);

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

                    throw;
                }
            }

            return(rowAffected);
        }