/// <summary> /// 取得帳號權限管理列表 /// </summary> /// <param name="searchModel"></param> /// <param name="pagination"></param> /// <returns></returns> public async Task <ResWithPaginationViewModel> GetUserList(UserSearchModel searchModel, PaginationViewModel pagination) { ResWithPaginationViewModel pageData = new ResWithPaginationViewModel(); List <UserViewModel> userlist = new List <UserViewModel>(); var query = from a in _db.user select new UserViewModel { ur_sn = a.ur_sn, ur_id = a.ur_id, ur_ac = a.ur_ac, ur_pw = a.ur_pw, ur_ct = a.ur_ct, ur_is = a.ur_is, ur_im = a.ur_im }; pageData.MaxDateTime = query.OrderByDescending(x => x.ur_ct).FirstOrDefault().ur_ct; pageData.MinDateTime = query.OrderBy(x => x.ur_ct).FirstOrDefault().ur_ct; if (searchModel.StartDateTime != null) { query = query.Where(x => x.ur_ct >= searchModel.StartDateTime); } if (searchModel.EndDateTime != null) { query = query.Where(x => x.ur_ct <= searchModel.EndDateTime); } if (!string.IsNullOrEmpty(searchModel.Query)) { switch (searchModel.SearchEnum) { case 0: query = query.Where(x => x.ur_ac.ToLower().Trim().Contains(searchModel.Query)); break; default: break; } } var _TotalCount = query.Count(); pageData.Pagination = new PaginationViewModel { PerPage = pagination.PerPage, CurrentPage = pagination.CurrentPage, TotalCounts = _TotalCount }; query = query .OrderByDescending(x => x.ur_ct) .Skip(pagination.GetSkipLength()) .Take(pagination.PerPage); if (query.Any()) { var list = query.OrderByDescending(x => x.ur_ct).ToList(); userlist = list; } pageData.Data = userlist; pageData.Success = true; return(await Task.Run(() => pageData)); }
/// <summary> /// 取得打卡列表 /// </summary> /// <param name="model"></param> /// <param name="pagination"></param> /// <returns></returns> public async Task <ResWithPaginationViewModel> GetCheckRecord(SearchCheckModel model, PaginationViewModel pagination) { ResWithPaginationViewModel pageData = new ResWithPaginationViewModel(); List <CheckRecordViewModel> check_inList = new List <CheckRecordViewModel>(); try { var query = from a in _check_in.GetAll() join b in _user.GetAll() on a.ur_id equals b.ur_id where a.ci_da >= model.StartDateTime && a.ci_da <= model.EndDateTime select new CheckRecordViewModel { ci_sn = a.ci_sn, ur_id = a.ur_id, ci_da = a.ci_da, ci_ut = a.ci_ut, ci_dt = a.ci_dt, ur_ac = b.ur_ac, ci_ct = a.ci_ct, Remark = a.Remark, ci_hr = a.ci_hr }; if (!string.IsNullOrEmpty(model.Query)) { var QueryString = model.Query.ToLower().Trim(); query = query.Where(x => x.ur_ac.ToLower().Trim().Contains(QueryString)); } if (!string.IsNullOrEmpty(model.ur_id)) { query = query.Where(x => x.ur_id == model.ur_id); } var _TotalCount = query.Count(); pageData.Pagination = new PaginationViewModel { PerPage = pagination.PerPage, CurrentPage = pagination.CurrentPage, TotalCounts = _TotalCount }; query = query .OrderByDescending(x => x.ci_da) .Skip(pagination.GetSkipLength()) .Take(pagination.PerPage); if (query.Any()) { check_inList = query.OrderByDescending(x => x.ci_da).ToList(); pageData.Data = check_inList; pageData.Success = true; pageData.Message = "取得打卡紀錄成功"; } else { pageData.Success = true; pageData.Message = "尚未有任何打卡紀錄"; } } catch { pageData.Success = false; pageData.Message = "取得打卡紀錄失敗"; } return(await Task.Run(() => pageData)); }