Esempio n. 1
0
        private Expression <Func <MD.tbl_Common_User, bool> > BuildSearchCriteria(VM.UserInfoSearch searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException("searchModel is null.");
            }

            Expression <Func <MD.tbl_Common_User, bool> > expr    = null;
            DynamicLambda <MD.tbl_Common_User>            builder = new DynamicLambda <MD.tbl_Common_User>();

            if (searchModel.BeginDate.HasValue)
            {
                Expression <Func <MD.tbl_Common_User, bool> > temp = s => s.CreatedDate >= searchModel.BeginDate;
                expr = builder.BuildQueryAnd(expr, temp);
            }
            if (searchModel.EndDate.HasValue)
            {
                Expression <Func <MD.tbl_Common_User, bool> > temp = s => s.CreatedDate <= searchModel.EndDate;
                expr = builder.BuildQueryAnd(expr, temp);
            }
            if (searchModel.LogonName != null)
            {
                Expression <Func <MD.tbl_Common_User, Boolean> > temp = s => s.LogonName.Contains(searchModel.LogonName);
                expr = builder.BuildQueryAnd(expr, temp);
            }
            if (searchModel.UserName != null)
            {
                Expression <Func <MD.tbl_Common_User, Boolean> > temp = s => s.UserName.Contains(searchModel.UserName);
                expr = builder.BuildQueryAnd(expr, temp);
            }

            return(expr);
        }
Esempio n. 2
0
        public IQueryable <VM.UserInfoItem> GetItems(VM.UserInfoSearch searchModel)
        {
            //Build search criteria lambda expression
            Expression <Func <MD.tbl_Common_User, Boolean> > expr = BuildSearchCriteria(searchModel);
            //if not set the sort way ,then the default set will be used.
            string sortBy        = "UserId";
            string sortDirection = "DESC";

            if (!string.IsNullOrWhiteSpace(searchModel.SortBy))
            {
                sortBy        = searchModel.SortBy;
                sortDirection = searchModel.SortDirection;
            }

            IQueryable <MD.tbl_Common_User> resultQueryable;

            resultQueryable = this.Ctx.tbl_Common_User;
            if (expr != null)
            {
                resultQueryable = resultQueryable.Where(expr).SortWith(sortBy, sortDirection).Where(m => m.IsDeleted != true);
            }
            else
            {
                resultQueryable = resultQueryable.SortWith(sortBy, sortDirection).Where(m => m.IsDeleted != true);
            }

            //filter tbl_Common_RoleUser then IsDeleted not be true
            IQueryable <MD.tbl_Common_RoleUser> roleUserQueryable;

            roleUserQueryable = this.Ctx.tbl_Common_RoleUser;
            roleUserQueryable = roleUserQueryable.Where(m => m.IsDeleted != true);

            var result = (from a in resultQueryable
                          join ru in roleUserQueryable on a.UserId equals ru.UserId into ruinner
                          from rui in ruinner.DefaultIfEmpty()
                          join r in Ctx.tbl_Common_Role on rui.RoleId equals r.RoleId into rinner
                          from ri in rinner.DefaultIfEmpty()
                          select new VM.UserInfoItem()
            {
                UserId = a.UserId,
                LogonName = a.LogonName,
                DomainAccount = a.DomainAccount,
                UserName = a.UserName,
                Password = a.Password,
                Status = a.Status,
                EmailAddress = a.EmailAddress,
                CreatedDate = a.CreatedDate,
                UpdatedDate = a.UpdatedDate,
                RoleId = rui.RoleId,
                RoleName = ri.Name
                           //GasStationName=a.tbl_Common_UserOfGasStation[0]
            });

            return(result);
        }
Esempio n. 3
0
        //
        // GET: /SystemMaint/UserInfo/
        public ActionResult Index(VM.UserInfoSearch search)
        {
            SetViewBage();
            ViewBag.IsSortable = true;
            var model = new VM.UserInfoModel();

            ViewBag.DisplayDate = BasicParam.DatetimeFormat;
            BL.UserInfo empBL = new BL.UserInfo();
            model.List   = empBL.GetItems(search);
            model.Search = search;
            if (Request.IsAjaxRequest())
            {
                return(PartialView("_List", model.List));
            }
            return(View(model));
        }
Esempio n. 4
0
        public IQueryable <VM.UserInfoItem> GetAllItemById(VM.UserInfoSearch searchModel)
        {
            //Build search criteria lambda expression
            Expression <Func <MD.tbl_Common_User, Boolean> > expr = BuildSearchCriteria(searchModel);
            //if not set the sort way ,then the default set will be used.
            string sortBy        = "UserId";
            string sortDirection = "DESC";

            if (!string.IsNullOrWhiteSpace(searchModel.SortBy))
            {
                sortBy        = searchModel.SortBy;
                sortDirection = searchModel.SortDirection;
            }
            IQueryable <MD.tbl_Common_User> resultQueryable;

            resultQueryable = this.Ctx.tbl_Common_User;
            if (expr != null)
            {
                resultQueryable = resultQueryable.Where(expr).SortWith(sortBy, sortDirection).Where(m => m.IsDeleted != true);
            }
            else
            {
                resultQueryable = resultQueryable.SortWith(sortBy, sortDirection).Where(m => m.IsDeleted != true);
            }

            var item = (from a in resultQueryable
                        join ru in Ctx.tbl_Common_RoleUser on a.UserId equals ru.UserId into ruinner
                        from rui in ruinner.DefaultIfEmpty()
                        join r in Ctx.tbl_Common_Role on rui.RoleId equals r.RoleId into rinner
                        from ri in rinner.DefaultIfEmpty()
                        where a.IsDeleted != true
                        select new VM.UserInfoItem
            {
                UserId = a.UserId,
                LogonName = a.LogonName,
                UserName = a.UserName,
                RoleId = rui.RoleId,
                RoleName = ri.Name,
                RoleIsDeleted = rui.IsDeleted,
            }

                        );


            return(item);
        }
Esempio n. 5
0
        public ActionResult GridView()
        {
            string json = Request.Params["searchModel"];

            VM.UserInfoSearch searchModel = new VM.UserInfoSearch();
            if (json != null)
            {
                try
                {
                    searchModel = JsonConvert.DeserializeObject(json, typeof(VM.UserInfoSearch)) as VM.UserInfoSearch;
                }
                catch
                {
                    return(Json("error", JsonRequestBehavior.AllowGet));
                }
            }
            BL.UserInfo empBL = new BL.UserInfo();
            var         model = empBL.GetItems(searchModel);

            ViewBag.DisplayDate = BasicParam.DatetimeFormat;
            return(PartialView("_List", model));
        }