public SearchResultObject <UserSearchResult> SearchUserTimeAttendance(UserSearchCondition searchCondition) { db = new TimeAttendanceEntities(); SearchResultObject <UserSearchResult> searchResult = new SearchResultObject <UserSearchResult>(); try { var listmodel = (from a in db.User.AsNoTracking() where a.DeleteFlg == Constants.DeleteFalse && (string.IsNullOrEmpty(searchCondition.Type) || a.Type.Equals(searchCondition.Type)) join c in db.UserGroup.AsNoTracking() on a.UserId equals c.UserId into ac from acv in ac.DefaultIfEmpty() join d in db.Group.AsNoTracking() on acv.GroupId equals d.GroupId into cd from cdv in cd.DefaultIfEmpty() select new UserSearchResult { UserId = a.UserId, UnitId = a.UnitId, Name = a.Name, FullName = a.FullName, BirthDay = a.BirthDay, Agency = a.Agency, Email = a.Email, Role = a.Role, PhoneNumber = a.PhoneNumber, Status = a.Status, Description = a.Description, ImageLink = a.ImageLink, CreateBy = a.CreateBy, CreateDate = a.CreateDate, UpdateBy = a.UpdateBy, UpdateDate = a.UpdateDate, GroupId = acv.GroupId, GroupName = cdv != null ? cdv.Name : string.Empty, Type = a.Type, }).AsQueryable(); if (!string.IsNullOrEmpty(searchCondition.GroupId)) { listmodel = listmodel.Where(r => r.GroupId.Equals(searchCondition.GroupId)); } if (!string.IsNullOrEmpty(searchCondition.Name)) { listmodel = listmodel.Where(r => r.Name.ToUpper().Contains(searchCondition.Name.ToUpper())); } if (!string.IsNullOrEmpty(searchCondition.FullName)) { listmodel = listmodel.Where(r => r.FullName.ToUpper().Contains(searchCondition.FullName.ToUpper())); } if (searchCondition.Status.HasValue) { listmodel = listmodel.Where(r => r.Status.HasValue && r.Status.Value == searchCondition.Status.Value); } if (!string.IsNullOrEmpty(searchCondition.UnitId)) { listmodel = listmodel.Where(r => r.UnitId.Equals(searchCondition.UnitId)); } if (!string.IsNullOrEmpty(searchCondition.Role)) { listmodel = listmodel.Where(r => r.Role.ToUpper().Contains(searchCondition.Role.ToUpper())); } if (searchCondition.Status.HasValue) { listmodel = listmodel.Where(r => r.Status.HasValue && r.Status.Value == searchCondition.Status.Value); } searchResult.TotalItem = listmodel.Select(r => r.UserId).Count(); var listResult = SQLHelpper.OrderBy(listmodel, searchCondition.OrderBy, searchCondition.OrderType).Skip((searchCondition.PageNumber - 1) * searchCondition.PageSize) .Take(searchCondition.PageSize) .ToList(); searchResult.ListResult = listResult; } catch (Exception ex) { throw new ErrorException(ErrorMessage.ERR001, ex.InnerException); } return(searchResult); }
public SearchResultObject <UserEventLogSearchResult> SearchUserEventLog(UserEventLogSearchCondition searchCondition, string saveOption) { db = new TimeAttendanceEntities(); SearchResultObject <UserEventLogSearchResult> searchResult = new SearchResultObject <UserEventLogSearchResult>(); try { var listmodel = (from a in db.UserEventLog.AsNoTracking() join b in db.User.AsNoTracking() on a.UserId equals b.UserId into ab from abv in ab.DefaultIfEmpty() select new UserEventLogSearchResult() { UserEventLogId = a.UserEventLogId, UserId = a.UserId, Description = a.Description, LogType = a.LogType, LogTypeName = a.LogType == 0 ? "Truy cập hệ thống" : "Khai thác dữ liệu", Type = abv.Type, CreateDate = a.CreateDate, UserName = abv.Name, FullName = abv.FullName }).AsQueryable(); if (!string.IsNullOrEmpty(searchCondition.UserName)) { listmodel = listmodel.Where(r => r.UserName != null && r.UserName.ToUpper().Contains(searchCondition.UserName.ToUpper())); } if (!string.IsNullOrEmpty(searchCondition.UserType)) { listmodel = listmodel.Where(r => r.Type != null && r.Type.Equals(searchCondition.UserType)); } if (!string.IsNullOrEmpty(searchCondition.UserIdSearch)) { listmodel = listmodel.Where(r => r.UserId != null && r.UserId.Equals(searchCondition.UserIdSearch)); } if (!string.IsNullOrEmpty(searchCondition.FullName)) { listmodel = listmodel.Where(r => r.FullName != null && r.FullName.ToUpper().Contains(searchCondition.FullName.ToUpper())); } if (!string.IsNullOrEmpty(searchCondition.Description)) { listmodel = listmodel.Where(r => r.Description.ToUpper().Contains(searchCondition.Description.ToUpper())); } if (searchCondition.LogType.HasValue) { listmodel = listmodel.Where(r => r.LogType.HasValue && r.LogType.Value == searchCondition.LogType.Value); } if (searchCondition.LogDateFrom.HasValue) { searchCondition.LogDateFrom = DateTimeUtils.ConvertDateFrom(searchCondition.LogDateFrom); listmodel = listmodel.Where(r => r.CreateDate.HasValue && r.CreateDate >= searchCondition.LogDateFrom); } if (searchCondition.LogDateTo.HasValue) { searchCondition.LogDateTo = DateTimeUtils.ConvertDateTo(searchCondition.LogDateTo); listmodel = listmodel.Where(r => r.CreateDate.HasValue && r.CreateDate <= searchCondition.LogDateTo); } searchResult.TotalItem = listmodel.Select(r => r.UserEventLogId).Count(); var listResult = SQLHelpper.OrderBy(listmodel, searchCondition.OrderBy, searchCondition.OrderType).Skip((searchCondition.PageNumber - 1) * searchCondition.PageSize) .Take(searchCondition.PageSize) .ToList(); string pathFile = string.Empty; if ((saveOption.Equals("PDF") || saveOption.Equals("XLSX")) && searchResult.TotalItem > 0) { if (searchResult.TotalItem > Constants.MAX_RETURN_DATA_ROW) { throw new BusinessException(ErrorMessage.ERR007); } else { pathFile = this.Export(saveOption, listmodel.ToList(), searchCondition); } } searchResult.ListResult = listResult; searchResult.PathFile = pathFile; } catch (Exception ex) { throw new ErrorException(ErrorMessage.ERR001, ex.InnerException); } return(searchResult); }