Пример #1
0
        public async Task ApplyTest()
        {
            var targetBlogApp = "xishuai2";
            var user          = new User
            {
                Alias       = "xishuai",
                DisplayName = "田园里的蟋蟀",
                Id          = 435188
            };
            var verfiyResult = await _applyAuthenticationService.VerfiyForBlogChange(user, targetBlogApp);

            Console.WriteLine(verfiyResult);
            Assert.Empty(verfiyResult);

            try
            {
                var blogChangeApply = new BlogChangeApply(targetBlogApp, "我要申请修改博客地址", user, "127.0.0.1");
                _unitOfWork.RegisterNew(blogChangeApply);
            }
            catch (ArgumentException ae)
            {
                Console.WriteLine(ae.Message);
                Assert.True(false);
            }
            Assert.True(await _unitOfWork.CommitAsync());
        }
        public async Task <SubmitResult> Apply(string targetBlogApp, string reason, string userLoginName, string ip)
        {
            var user = await UserService.GetUserByLoginName(userLoginName);

            var verfiyResult = await _applyAuthenticationService.VerfiyForBlogChange(user, targetBlogApp);

            if (!string.IsNullOrEmpty(verfiyResult))
            {
                return(new SubmitResult {
                    IsSucceed = false, Message = verfiyResult
                });
            }
            try
            {
                var blogChangeApply = new BlogChangeApply(targetBlogApp, reason, user, ip);
                _unitOfWork.RegisterNew(blogChangeApply);
                return(new SubmitResult {
                    IsSucceed = await _unitOfWork.CommitAsync()
                });
            }
            catch (ArgumentException ae)
            {
                return(new SubmitResult {
                    IsSucceed = false, Message = ae.Message
                });
            }
            catch (Exception ex)
            {
                return(new SubmitResult {
                    IsSucceed = false, Message = ex.Message
                });
            }
        }