public AssignmentFilterModel GetFilterModel() { if (IsPostBack) { return(GetAssignmentsWithCustomFilter()); } var filter = new AssignmentFilter(); int count = WorkflowInit.Runtime.PersistenceProvider.GetAssignmentCountAsync(filter).Result; List <Assignment> assignments = WorkflowInit.Runtime.AssignmentApi.GetAssignmentsAsync(filter, new Paging(1, PageSize)).Result; Count = count; PageNumber = 1; AssignmentsTableRepeater.DataSource = GetAssignmentModels(assignments); AssignmentsTableRepeater.DataBind(); return(new AssignmentFilterModel()); }
private AssignmentFilterModel GetAssignmentsWithCustomFilter() { var model = new AssignmentFilterModel() { FilterName = Request.Form[$"{Master.UniqueID}$MainContent$formFilter$FilterName"], AssignmentCode = Request.Form[$"{Master.UniqueID}$MainContent$formFilter$AssignmentCode"], StatusState = Request.Form[$"{Master.UniqueID}$MainContent$formFilter$StatusState"], Page = Int32.Parse(Request.Form[$"{Master.UniqueID}$MainContent$formFilter$Page"]), }; var isCorrect = Int32.TryParse(Request.Form[$"{Master.UniqueID}$MainContent$formFilter$DocumentNumber"], out int documentNumber); model.DocumentNumber = isCorrect ? documentNumber : (int?)null; Guid identityId = CurrentUserSettings.GetCurrentUser(); var assignmentFilters = GenerateFilters(identityId.ToString()); AssignmentFilter customFilter; if (assignmentFilters.TryGetValue(model.FilterName, out var res)) { customFilter = res; if (model.DocumentNumber != null) { var doc = DocumentRepository.GetByNumber((int)model.DocumentNumber); if (doc != null) { customFilter.ProcessIdEqual(doc.Id); } else { customFilter.ProcessIdEqual(Guid.Empty); } } if (!model.AssignmentCode.IsNullOrWhiteSpace()) { customFilter.CodeEquals(model.AssignmentCode); } if (model.StatusState != "Any") { customFilter.StatusStateEquals(model.StatusState); } } else { customFilter = new AssignmentFilter(); model = new AssignmentFilterModel() { Page = model?.Page ?? 1 }; } int count = WorkflowInit.Runtime.PersistenceProvider.GetAssignmentCountAsync(customFilter).Result; model.Page = model?.Page ?? 1; var maxPage = Math.Ceiling(count / (decimal)PageSize); if (model.Page > maxPage) { model.Page = (int)maxPage; } List <Assignment> assignments = WorkflowInit.Runtime.AssignmentApi.GetAssignmentsAsync(customFilter, new Paging(model.Page, PageSize)).Result; Count = count; PageNumber = model.Page; AssignmentsTableRepeater.DataSource = GetAssignmentModels(assignments); AssignmentsTableRepeater.DataBind(); return(model); }