TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Olivier Muhring
NA
150
10k
ASP .NET Core Model validation through services and with >1 parameter
Feb 5 2021 1:42 PM
For a project I have a web page which allows me to link people to specific juror functions for an assortment of "matches" that are being played on a given date.
Basically, the page shows a series of juror panels, each panel represents a specific game/match that is being helped on that day.
A panel consists of a listing of juror functions, the user then has to select a juror member for each function. The user can also leave a function unassigned, but each selected juror can only perform 1 task for the given day.
The required functions vary from game to game, so nothing of is it really fixed.
When they've selected the jurors and click on the "post" button the following model is sent back for processing:
public
class
PanelModel
{
#region Properties
public
int
WedstrijdSessie {
get
;
set
; }
public
string
PanelName {
get
;
set
; }
public
string
ClubName {
get
;
set
; }
public
List<JuryOpgaveProposition> PanelComposition {
get
;
set
; }
public
SelectList JuryMembers {
get
;
set
; }
#endregion
}
The Property PanelComposition consists of a list of the following objects:
public
class
JuryOpgaveProposition
{
#region Properties
public
int
? FK_WedstrijdSessie {
get
;
set
; }
public
int
? SK_JuryOpgave {
get
;
set
; }
public
int
? FK_Jury {
get
;
set
; }
public
string
Omschrijving {
get
;
set
; }
public
string
Functie {
get
;
set
; }
public
string
Naam {
get
;
set
; }
public
string
Voornaam {
get
;
set
; }
public
string
JuryNiveau {
get
;
set
; }
public
int
? JuryNiveauNr {
get
;
set
; }
public
int
? SK_Club {
get
;
set
; }
public
string
Club {
get
;
set
; }
public
int
? Vlg_PositieToegekend {
get
;
set
;}
#endregion
#region Calculated properties
public
string
JuryName => $
"{Voornaam} {Naam}"
;
#endregion
}
Anyway, the only data they can change on the page are the functions, which are being represented here by a listing of
JuryOpgaveProposition
-objects.
Now... before I can accept this I have - of course - to validate the data they can be sent:
- Each juror has to be unique in the panel.
- Each juror has to be free for being selected.
The listing being proposed to the user is a listing of the jurors that are available for that day, but some of them may already be judging a different game.
To make it more user friendly validation errors have to be shown on the screen, right next to the selected juror.
I know I can do this with ASP .NET validation, but I'm struggling a bit.
Problem 1:
I need to create custom validators which allows me to display an error for each juror, but most of the examples I have found build a listing of errors which I can then show on the top or the bottom of the screen. In this case however I want to be able to show the error right next to the validated fields, like I would be able to do with the built-in validators (the one for credit card numbers for example).
Problem 2:
Both validators require me to access the database.
And... all my database access is currently being handled through the use of services. The examples I've found assume the entities exist within the ASP .NET project and are accessed there. Which is not the idea here. How do I get past this?
Problem 3:
Both validators would need the queries to filter on multiple parameters. The examples I've found don't show how I can pass extra parameters to the validator.
I hope anyone here can help me. :-)
Reply
Answers (
2
)
How to Unzip Data On Client Side ?
how to implement repository pattern in asp.net mvc project?