public Task BindModelAsync(ModelBindingContext bindingContext) { //Recuperiamo i valori grazie ai value provider string search = bindingContext.ValueProvider.GetValue("Search").FirstValue; string orderBy = bindingContext.ValueProvider.GetValue("OrderBy").FirstValue; int.TryParse(bindingContext.ValueProvider.GetValue("Page").FirstValue, out int page); bool.TryParse(bindingContext.ValueProvider.GetValue("Ascending").FirstValue, out bool ascending); //Creiamo l'istanza del CourseListInputModel CoursesOptions options = coursesOptions.CurrentValue; CourseListInputModel inputModel = new(search, page, orderBy, ascending, options.PerPage, options.Order); //Impostiamo il risultato per notificare che la creazione รจ avvenuta con successo bindingContext.Result = ModelBindingResult.Success(inputModel); //Restituiamo un task completato return(Task.CompletedTask); }
//IOptionsMonitor<CoursesOptions> coursesOptions public CourseListInputModel(string search, int page, string orderby, bool ascending, CoursesOptions coursesOptions) { if (!coursesOptions.Orderd.Allow.Contains(orderby)) { orderby = coursesOptions.Orderd.By; ascending = coursesOptions.Orderd.Ascending; } page = Math.Max(1, page); //Prende il valore massimo tra i due passati string direction = ascending ? "ASC" : "DESC"; Search = search; Page = page; OrderBy = orderby; Ascending = ascending; Limit = (int)coursesOptions.PerPage; Offset = (page - 1) * Limit; }