Пример #1
0
        public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Topic        = CreateBuild(request.Topic, request.LoginSession);
                        request.Topic.IsUsed = true;
                        var topicId = await topicRepository.AddAsync(request.Topic);

                        // languages
                        foreach (var item in request.Topic.TopicLanguages)
                        {
                            item.TopicId = topicId;
                            await topicRepository.AddOrUpdateLanguage(item);
                        }
                        rs = 0;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }
Пример #2
0
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Topic == null || request.Topic.Id == 0)
            {
                throw new BusinessException("Topic.NotExisted");
            }

            var topic = (await topicQueries.GetTopicById(request.Topic.Id));

            if (topic == null)
            {
                throw new BusinessException("Topic.NotExisted");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        //request.Topic.CreatedDate = topic.CreatedDate;
                        //request.Topic.CreatedBy = topic.CreatedBy;
                        request.Topic = UpdateBuild(request.Topic, request.LoginSession);

                        rs = await topicRepository.UpdateAsync(request.Topic);

                        if (rs != 0)
                        {
                            return(-1);
                        }

                        //for language
                        // languages
                        foreach (var item in request.Topic.TopicLanguages)
                        {
                            item.TopicId = request.Topic.Id;
                            await topicRepository.AddOrUpdateLanguage(item);
                        }


                        rs = 0;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        if (rs == 0)
                        {
                            trans.Commit();
                        }
                        else
                        {
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                        }
                    }
                }
            }

            return(rs);
        }