public CommonSearchView <MasterInquiryUserData> InquiryUsers(MasterInquiryUserParam model) { using (var ctx = new ConXContext()) { //define model view CommonSearchView <MasterInquiryUserData> view = new ModelViews.CommonSearchView <ModelViews.MasterInquiryUserData>() { pageIndex = model.pageIndex - 1, itemPerPage = model.itemPerPage, totalItem = 0, datas = new List <ModelViews.MasterInquiryUserData>() }; //query data List <User> users = ctx.Users .Include("userRole") .Include("department") .Include("userBranchPrvlgList") .Where(x => (x.username.Contains(model.username) || model.username == null) && (x.name.Contains(model.name) || model.name == null) && (x.userRoleId == model.userrole || model.userrole == 0) && (x.statusId == model.statusId || model.statusId == null) && (x.userBranchPrvlgList.Any(y => model.branchList.Contains(y.branchId)) || model.branchList.Count == 0) //&& (x.userBranchPrvlgList.Any(y => y.branchId == model.branchId)) && x.isPC == model.isPC //&& (x.createUser == model.createUser || model.createUser.ToLower() == "admin") ) .OrderBy(o => o.username) .ToList(); //count , select data from pageIndex, itemPerPage view.totalItem = users.Count; users = users.Skip(view.pageIndex * view.itemPerPage) .Take(view.itemPerPage) .ToList(); //prepare model to modelView foreach (var i in users) { view.datas.Add(new ModelViews.MasterInquiryUserData() { username = i.username, name = i.name, isPC = i.isPC, userRoleDesc = i.userRole != null ? i.userRole.roleName : null, createUser = i.createUser, createdDate = i.createDatetime, statusId = i.statusId, departmentDesc = i.department != null ? i.department.departmentName : null }); } //return data to contoller return(view); } }
public HttpResponseMessage inquiry(MasterInquiryUserParam model) { try { model.username = model.username.Trim(); model.name = model.name.Trim(); var result = userService.InquiryUsers(model); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.ToString())); } }