Beispiel #1
0
        static void Main(string[] args)
        {
            //var dt = DateTime.Today;
            //var isActive = true;
            //Expression<Func<Student, bool>> expr = s => (s.CreateAt > dt || s.UpdateAt > dt) &&
            //                                            s.IsDel &&
            //                                            true &&
            //                                            isActive &&
            //                                            s.School.SchoolName.Contains("测试") &&
            //                                            s.CreateAt < s.UpdateAt &&
            //                                            s.Birthday == null;
            ////Expression<Func<Student, bool>> expr = s => isActive && s.Birthday != null && true;

            //var resolver = new ConditionResolver(MyEntityContainer.Get(typeof(Student)));

            //resolver.Resolve(expr.Body);
            //Console.WriteLine(resolver.GetCondition());

            //var parameters = resolver.GetParameters();
            //foreach (var parameter in parameters)
            //{
            //    Console.WriteLine($"{parameter.Key} : {parameter.Value}");
            //}


            //var search = LinqExtensions.False<Student>();
            //search = search.And(s => s.CreateAt > dt || s.UpdateAt > dt);
            //search = search.And(s => !s.IsDel);
            //search = search.And(s => s.School.SchoolName.Contains("测试"));

            //var visitor = new WhereExpressionVisitor<Student>();
            //visitor.Visit(expr);

            //Console.WriteLine(visitor.GetCondition());

            //var parameters = visitor.GetParameters();
            //foreach (var parameter in parameters)
            //{
            //    Console.WriteLine($"{parameter.Key} = {parameter.Value}");
            //}

            //Console.WriteLine("======================");

            //var visitor2 = new WhereExpressionVisitor<Student>();
            //visitor2.Visit(search);

            //Console.WriteLine(visitor2.GetCondition());
            //var parameters2 = visitor2.GetParameters();
            //foreach (var parameter in parameters2)
            //{
            //    Console.WriteLine($"{parameter.Key} = {parameter.Value}");
            //}

            Expression <Func <Student, object> > expr = s => new { s.StudentName, s.FKSchoolId };

            Expression <Func <Student, object> > expr2 = s => s.StudentName;

            var visitor1 = new ObjectExpressionVisitor(MyEntityContainer.Get(typeof(Student)));

            visitor1.Visit(expr);

            var visitor2 = new ObjectExpressionVisitor(MyEntityContainer.Get(typeof(Student)));

            visitor1.Visit(expr2);

            var kvs1 = visitor1.GetPropertyList();

            foreach (var kv in kvs1)
            {
                Console.WriteLine($"{kv.Key}-{kv.Value}");
            }

            var kvs2 = visitor2.GetPropertyList();

            foreach (var kv in kvs2)
            {
                Console.WriteLine($"{kv.Key}-{kv.Value}");
            }

            var student = new Student();

            var db = MyDb.New("").Update <Student>(student,
                                                   s => new { s.FKSchoolId, s.StudentName });

            Console.Read();
        }
Beispiel #2
0
        public IActionResult UserInfoCallback(string code, string returnUrl)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                return(RedirectToAction("Index", "Error", new { title = "无效访问", message = "您的请求参数不合法,请从正规渠道访问此功能。" }));
            }

            try
            {
                var token = AccessTokenContainer.TryGetToken(_corpId, _secret);
                if (string.IsNullOrWhiteSpace(token))
                {
                    //_log.Error("获取ACCESSTOKEN详情失败:AccessTokenContainer.TryGetToken()获取失败");
                    return(RedirectToAction("Index", "Error", new { title = "访问失败", message = "从微信服务端请求数据失败,请稍候再试。" }));
                }

                var user = OAuth2Api.GetUserId(token, code);
                if (user.errcode != Senparc.Weixin.ReturnCode_Work.请求成功)
                {
                    //_log.Error("获取用户ID失败:" + user.errmsg);
                    return(RedirectToAction("Index", "Error", new { title = "加载失败", message = "从微信服务端获取用户信息失败,请联系管理员或稍候再试" }));
                }

                if (string.IsNullOrWhiteSpace(user.UserId))
                {
                    //_log.Error("获取用户ID失败,接口调用成功,但USERID为空:" + JsonConvert.SerializeObject(user));
                    return(RedirectToAction("Index", "Error", new { title = "拒绝访问", message = "仅限企业微信内部员工使用,未能获取到您的数据,请联系管理员" }));
                }
                else
                {
                    var db      = MyDb.New();
                    var appUser = db.Load <AppUser>(a => a.No == user.UserId);

                    if (appUser == null)
                    {
                        return(RedirectToAction("Index", "Error", new { title = "访问失败", message = "无权访问,请联系管理员" }));
                    }
                    else
                    {
                        var dto = new UserDto {
                            No = appUser.No, Name = appUser.Name, DepartmentId = appUser.DepartmentId
                        };
                        if (appUser.IsFinance)
                        {
                            dto.Role = "audit";
                        }
                        else
                        {
                            dto.Role = appUser.IsMaster ? "master" : "user";
                        }

                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.NameIdentifier, dto.No),
                            new Claim(ClaimTypes.Name, dto.Name),
                            new Claim(ClaimTypes.Role, dto.Role),
                            new Claim("Department", dto.DepartmentId.ToString())
                        };

                        HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
                        HttpContext.SignInAsync(
                            new ClaimsPrincipal(
                                new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme)
                                )
                            );

                        return(Redirect(returnUrl));
                    }
                }
            }
            catch (Exception ex)
            {
                //_log.Error(ex);
                return(RedirectToAction("Index", "Error", new { title = "访问失败", message = "系统错误:" + ex.Message + ",请联系管理员" }));
            }
        }
Beispiel #3
0
 public ApprovalsController(IMapper mapper)
 {
     _db      = MyDb.New();
     _mapper  = mapper;
     _service = new ApprovalService(_mapper);
 }