protected virtual Task <bool> ValidateFilter(DeveloperFilterModel filter) { //if (!filter.Set.HasValue) //{ // ModelState.AddModelError(nameof(filter.Set), String.Format("Unrecognizable set was requested \"{0}\"", filter.Set)); //} //if (!filter.Sort.HasValue) //{ // ModelState.AddModelError(nameof(filter.Set), String.Format("Unrecognizable sort column was requested \"{0}\"", filter.Sort)); //} //if retriving associated data (devs of project) and context not given or project does't exist if ((filter.Set.Value == DeveloperSet.Associated || filter.Set.Value == DeveloperSet.NonAssociated) && string.IsNullOrEmpty(filter.ProjectContextUrl)) { ModelState.AddModelError(nameof(filter.ProjectContextUrl), string.Format("Project url not provided in \"{0}\" field of request object", nameof(filter.ProjectContextUrl))); } // not sure where it goes //else if (!await _mng.ProjectExists(Decode(filter.Context))) //{ // ModelState.AddModelError(nameof(filter.Context), string.Format("Project with name {0} was not found", Decode(filter.Context))); //} return(Task.FromResult <bool>(ModelState.IsValid)); }
protected virtual void SetFilterDefaults(DeveloperFilterModel filter) { if (!filter.Set.HasValue) { filter.Set = DeveloperSet.All; } if (!filter.Sort.HasValue) { filter.Sort = DeveloperSort.FullName; } if (!filter.Order.HasValue) { filter.Order = OrderDirection.Ascending; } if (!filter.Skip.HasValue || filter.Skip.Value < 0) { filter.Skip = 0; } if (!filter.Take.HasValue || filter.Take.Value < 0) { filter.Take = DefaultTake; } if (filter.Set.Value != DeveloperSet.Associated && filter.Set.Value != DeveloperSet.NonAssociated) { filter.ProjectContextUrl = ""; } }
public static OrderModel GetOrderModel(this DeveloperFilterModel filter) { return(new OrderModel { SortColumn = filter.Sort.Value.ToString(), isAscendingOrder = filter.Order.Value == OrderDirection.Ascending, Skip = filter.Skip.Value, Take = filter.Take.Value }); }
public async Task <IActionResult> Get([FromQuery] DeveloperFilterModel filter) { SetFilterDefaults(filter); if (!await ValidateFilter(filter)) { return(BadRequest(ModelState.GetValidationProblemDetails())); } var developers = await GetSetOrAll(filter); string projectUrl = filter.Set.Value == DeveloperSet.Associated ? filter.ProjectContextUrl : ""; return(Ok(new PaginationCollection <EditDeveloperViewModel>() { Values = developers.Select(x => x.GetVM(Encode(x.Nickname), projectUrl)).ToArray(), TotalCount = _developerRepo.LastQueryTotalCount })); }
protected virtual Task <IEnumerable <Developer> > GetSetOrAll(DeveloperFilterModel filter) { if (filter.Set.Value == DeveloperSet.Associated) { return(_developerRepo.GetAssignedTo( projName: Decode(filter.ProjectContextUrl), keywords: filter.Keywords, order: filter.GetOrderModel())); } if (filter.Set.Value == DeveloperSet.NonAssociated) { return(_developerRepo.GetAssignableTo( projName: Decode(filter.ProjectContextUrl), keywords: filter.Keywords, order: filter.GetOrderModel())); } return(_developerRepo.Get(filter.Keywords, filter.GetOrderModel())); }