public ActionResult SearchUserAssign(UserAssignSearchFilter searchFilter) { Logger.Info(_logMsg.Clear().SetPrefixMsg("User Monitoring :: Search UserAssign").ToInputLogString()); try { if (ModelState.IsValid) { searchFilter.CurrentUserId = UserInfo.UserId; _userMonitoringFacade = new UserMonitoringFacade(); var viewModel = new SearchUserAssignViewModel(); viewModel.SearchFilter = searchFilter; viewModel.ResultList = _userMonitoringFacade.SearchUserAssign(searchFilter); ViewBag.PageSize = viewModel.SearchFilter.PageSize; using (var stFacadce = new SrStatusFacade()) { ViewBag.SRStateList = stFacadce.GetSrState() .Where(x => !x.SRStateId.InList(Constants.SRStateId.Cancelled, Constants.SRStateId.Closed)) .ToList(); } Logger.Info(_logMsg.Clear().SetPrefixMsg("User Monitoring :: Search UserAssign").ToSuccessLogString()); return(PartialView("~/Views/UserMonitoring/_SearchUserAssign.cshtml", viewModel)); } return(Json(new { Valid = false, Error = string.Empty, Errors = GetModelValidationErrors() })); } catch (Exception ex) { Logger.Error("Exception occur:\n", ex); Logger.Info(_logMsg.Clear().SetPrefixMsg("User Monitoring :: Search UserAssign").Add("Error Message", ex.Message).ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }
public ActionResult SearchUserAssign(UserAssignSearchFilter searchFilter) { Logger.Info(_logMsg.Clear().SetPrefixMsg("User Monitoring >> Search User Assign").ToInputLogString()); try { if (ModelState.IsValid) { searchFilter.CurrentUserId = UserInfo.UserId; _userMonitoringFacade = new UserMonitoringFacade(); var viewModel = new SearchUserAssignViewModel(); viewModel.SearchFilter = searchFilter; viewModel.ResultList = _userMonitoringFacade.SearchUserAssign(searchFilter); ViewBag.PageSize = viewModel.SearchFilter.PageSize; Logger.Info(_logMsg.Clear().SetPrefixMsg("User Monitoring >> Search User Assign").ToSuccessLogString()); return(PartialView("~/Views/UserMonitoring/_SearchUserAssign.cshtml", viewModel)); } return(Json(new { Valid = false, Error = string.Empty, Errors = GetModelValidationErrors() })); } catch (Exception ex) { Logger.Info(_logMsg.Clear().SetPrefixMsg("User Monitoring >> Search User Assign").ToFailLogString()); return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString()))); } }
private static IQueryable <UserAssignEntity> SetUserAssignSort(IQueryable <UserAssignEntity> resultList, UserAssignSearchFilter searchFilter) { if (string.IsNullOrEmpty(searchFilter.SortOrder)) { searchFilter.SortOrder = "ASC"; } if (string.IsNullOrEmpty(searchFilter.SortField)) { searchFilter.SortField = "UserFirstname"; } if (searchFilter.SortOrder.ToUpper(CultureInfo.InvariantCulture).Equals("ASC")) { switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture)) { default: return(resultList.OrderByDescending(a => a.IsCurrentUser).ThenBy(a => a.UserFirstname)); } } else { switch (searchFilter.SortField.ToUpper(CultureInfo.InvariantCulture)) { default: return(resultList.OrderByDescending(a => a.UserFirstname)); } } }
public List <UserAssignEntity> SearchUserAssign(UserAssignSearchFilter searchFilter) { var currentUserId = searchFilter.CurrentUserId; //var userIds = searchFilter.UserIds.Split(',').Select(Int32.Parse).ToList(); var ignoreStatusList = new int?[] { Constants.SRStatusId.Cancelled, Constants.SRStatusId.Closed }; var userIds = StringHelpers.ConvertStringToList(searchFilter.UserIds, ',').Select(x => Int32.Parse((string)x)).ToList(); var fromDate = searchFilter.AssignDateFromValue.HasValue ? searchFilter.AssignDateFromValue.Value.Date : new Nullable <DateTime>(); var toDate = searchFilter.AssignDateToValue.HasValue ? searchFilter.AssignDateToValue.Value.Date : new Nullable <DateTime>(); var query = from user in _context.TB_R_USER from role in _context.TB_C_ROLE.Where(x => x.ROLE_ID == user.ROLE_ID).DefaultIfEmpty() from branch in _context.TB_R_BRANCH.Where(x => x.BRANCH_ID == user.BRANCH_ID).DefaultIfEmpty() where (userIds.Contains(user.USER_ID) && user.STATUS == 1) && user.IS_GROUP == false && (!searchFilter.BranchId.HasValue || user.BRANCH_ID == searchFilter.BranchId.Value) select new UserAssignEntity() { IsCurrentUser = (user.USER_ID == currentUserId), UserId = user.USER_ID, RoleName = role.ROLE_NAME, Username = user.USERNAME, UserPositionCode = user.POSITION_CODE, UserFirstname = user.FIRST_NAME, UserLastname = user.LAST_NAME, BranchName = branch.BRANCH_NAME, OwnerSrList = (from sr in _context.TB_T_SR where sr.OWNER_USER_ID.HasValue && sr.OWNER_USER_ID.Value == user.USER_ID && (!searchFilter.ProductId.HasValue || sr.PRODUCT_ID == searchFilter.ProductId.Value) && (!searchFilter.CampaignServiceId.HasValue || sr.CAMPAIGNSERVICE_ID == searchFilter.CampaignServiceId.Value) && (!searchFilter.AreaId.HasValue || sr.AREA_ID == searchFilter.AreaId.Value) && (!searchFilter.SubAreaId.HasValue || sr.SUBAREA_ID == searchFilter.SubAreaId.Value) && (!fromDate.HasValue || EntityFunctions.TruncateTime(sr.CREATE_DATE.Value) >= fromDate.Value) && (!toDate.HasValue || EntityFunctions.TruncateTime(sr.CREATE_DATE.Value) <= toDate.Value) //&& sr.SR_STATUS_ID != Constants.SRStatusId.Cancelled //&& sr.SR_STATUS_ID != Constants.SRStatusId.Closed && !ignoreStatusList.Contains(sr.SR_STATUS_ID) select new ServiceRequestWithStatusEntity { SrId = sr.SR_ID, SrStatusCode = sr.TB_C_SR_STATUS.SR_STATUS_CODE }).ToList(), DelegateSrList = (from sr in _context.TB_T_SR where sr.DELEGATE_USER_ID.HasValue && sr.DELEGATE_USER_ID.Value == user.USER_ID && (!searchFilter.ProductId.HasValue || sr.PRODUCT_ID == searchFilter.ProductId.Value) && (!searchFilter.CampaignServiceId.HasValue || sr.CAMPAIGNSERVICE_ID == searchFilter.CampaignServiceId.Value) && (!searchFilter.AreaId.HasValue || sr.AREA_ID == searchFilter.AreaId.Value) && (!searchFilter.SubAreaId.HasValue || sr.SUBAREA_ID == searchFilter.SubAreaId.Value) && (!fromDate.HasValue || EntityFunctions.TruncateTime(sr.CREATE_DATE.Value) >= fromDate.Value) && (!toDate.HasValue || EntityFunctions.TruncateTime(sr.CREATE_DATE.Value) <= toDate.Value) //&& sr.SR_STATUS_ID != Constants.SRStatusId.Cancelled //&& sr.SR_STATUS_ID != Constants.SRStatusId.Closed && !ignoreStatusList.Contains(sr.SR_STATUS_ID) select new ServiceRequestWithStatusEntity { SrId = sr.SR_ID, SrStatusCode = sr.TB_C_SR_STATUS.SR_STATUS_CODE }).ToList(), CreateSrList = (from sr in _context.TB_T_SR where sr.CREATE_USER.HasValue && sr.CREATE_USER.Value == user.USER_ID && (!searchFilter.ProductId.HasValue || sr.PRODUCT_ID == searchFilter.ProductId.Value) && (!searchFilter.CampaignServiceId.HasValue || sr.CAMPAIGNSERVICE_ID == searchFilter.CampaignServiceId.Value) && (!searchFilter.AreaId.HasValue || sr.AREA_ID == searchFilter.AreaId.Value) && (!searchFilter.SubAreaId.HasValue || sr.SUBAREA_ID == searchFilter.SubAreaId.Value) && (!fromDate.HasValue || EntityFunctions.TruncateTime(sr.CREATE_DATE.Value) >= fromDate.Value) && (!toDate.HasValue || EntityFunctions.TruncateTime(sr.CREATE_DATE.Value) <= toDate.Value) //&& sr.SR_STATUS_ID != Constants.SRStatusId.Cancelled //&& sr.SR_STATUS_ID != Constants.SRStatusId.Closed && !ignoreStatusList.Contains(sr.SR_STATUS_ID) select new ServiceRequestWithStatusEntity { SrId = sr.SR_ID, SrStatusCode = sr.TB_C_SR_STATUS.SR_STATUS_CODE }).ToList(), }; int startPageIndex = (searchFilter.PageNo - 1) * searchFilter.PageSize; searchFilter.TotalRecords = query.Count(); if (startPageIndex >= searchFilter.TotalRecords) { startPageIndex = 0; searchFilter.PageNo = 1; } query = SetUserAssignSort(query, searchFilter); return(query.Skip(startPageIndex).Take(searchFilter.PageSize).ToList <UserAssignEntity>()); }
public List <UserAssignEntity> SearchUserAssign(UserAssignSearchFilter searchFilter) { var dataAccess = new UserMonitoringDataAccess(_context); return(dataAccess.SearchUserAssign(searchFilter)); }