public async Task <APIResult> GetPageById(int pageId)
        {
            var rs = await pageHomepageQueries.GetPageByIdAsync(pageId);

            return(new APIResult()
            {
                Result = 0,
                Data = rs
            });
        }
Beispiel #2
0
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Page == null || request.Page.Id == 0)
            {
                throw new BusinessException("Page.NotExisted");
            }

            var page = (await pageQueries.GetPageByIdAsync(request.Page.Id));

            if (page == null)
            {
                throw new BusinessException("Page.NotExisted");
            }

            var rs = -1;

            using (var conn = DALHelper.GetConnection())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    try
                    {
                        request.Page = UpdateBuild(request.Page, request.LoginSession);

                        rs = await pageRepository.UpdateAsync(request.Page);

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

                        //for language
                        // languages
                        foreach (var item in request.Page.PageLanguages)
                        {
                            item.PageId = request.Page.Id;
                            await pageRepository.AddOrUpdateLanguage(item);
                        }


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

            return(rs);
        }