Exemplo n.º 1
0
        public Resp_Index <CaptureDTO> Index(Req_Index request)
        {
            var response = new Resp_Index <CaptureDTO>();
            var limits   = _sysRightRepository.GetRightByUserWithModule(request.userId, request.moduleId).ConvertoDto <SysUserRightView, SysModuleOperateIndexDTO>().ToList();

            if (limits.IsNotNull() && limits.Count > 0 && limits.Find(s => s.IsValid == 1).IsNotNull())
            {
                response.allowVisit      = true;
                response.moduleOperaties = limits.OrderByDescending(t => t.IsValid).GroupBy(t => new { t.KeyCode, t.KeyName }).Select(s => new SysModuleOperateIndexDTO
                {
                    KeyCode = s.Key.KeyCode,
                    KeyName = s.Key.KeyName,
                    IsValid = s.Sum(x => x.IsValid),
                }).ToList();
                var query_parameter = new Capture_Query {
                    PgIndex = 1, PgSize = request.PgSize
                };
                response.query = Query(query_parameter);
            }
            else
            {
                _sysRightRepository.UnitOfWork.Commite();
                response.allowVisit = false;
                response.message    = "无访问权限,请联系管理员";
            }

            return(response);
        }
Exemplo n.º 2
0
        public Resp_Query <CaptureDTO> Query(Capture_Query request)
        {
            var records  = _repository.GetAll();
            var response = new Resp_Query <CaptureDTO>();

            records.ToMaybe()
            .Do(d => request.Verify())
            .DoWhen(t => !string.IsNullOrEmpty(request.CarNumber), d => records = records.Where(s => s.CarNumber.Contains(request.CarNumber.Trim())))
            .DoWhen(t => !string.IsNullOrEmpty(request.Channel), d => records   = records.Where(s => s.Channel.Equals(request.Channel)))
            .DoWhen(t => !string.IsNullOrEmpty(request.ParkId), d => records    = records.Where(s => s.ParkId.Contains(request.ParkId.Trim())));
            //.DoWhen(t => !string.IsNullOrEmpty(request.Type), d => records = records.Where(s => s.BeiAn == request.Type));


            if (!string.IsNullOrEmpty(request.Type) && int.TryParse(request.Type, out int typeresult))
            {
                records = records.Where(s => s.BeiAn == typeresult);
            }


            if (!string.IsNullOrEmpty(request.Pass) && int.TryParse(request.Pass, out int result))
            {
                if (result == 2)
                {
                    records = records.Where(s => s.Pass == 1 && s.WithOut == 0);
                }
                else
                {
                    records = records.Where(s => s.Pass == result);
                }
            }

            if (!string.IsNullOrEmpty(request.StayHours) && int.TryParse(request.StayHours, out int stayHours))
            {
                var dt = DateTime.Now.AddHours(-stayHours);
                records = records.Where(t => t.CreateTime < dt);
            }

            if (!string.IsNullOrEmpty(request.BeginTime) && DateTime.TryParse(request.BeginTime, out DateTime start))  //Linq to entity 不支持datatime.parse函数
            {
                records = records.Where(s => s.CreateTime >= start);
            }

            if (!string.IsNullOrEmpty(request.EndTime) && DateTime.TryParse(request.EndTime, out DateTime end))
            {
                records = records.Where(s => s.CreateTime <= end);
            }

            response.totalCounts = records.Count();
            response.totalRows   = (int)Math.Ceiling((double)response.totalCounts / request.PgSize);

            if (!string.IsNullOrEmpty(request.Order))
            {
                records = records.DataSorting(request.Order, request.Esc);
            }
            else
            {
                records = records.OrderByDescending(o => o.ID);
            }

            response.entities = records.Skip(request.PgSize * (request.PgIndex - 1)).Take(request.PgSize).ToList().ConvertoDto <Capture, CaptureDTO>().ToList();
            return(response);
        }