This is a migrated thread and some comments may be shown as answers.
Validate Resources
1 Answer 19 Views
This is a migrated thread and some comments may be shown as answers.
Heiko
Top achievements
Rank 1
Veteran
Heiko asked on 09 Oct 2012, 04:27 PM
I have a custom appointment and I want to validate if any resources are checked. I can find no way to check this before the OK button is clicked. In this forum I found an example so here is what I did:

public partial class dbAppointment : IAppointment, IExtendedAppointment,  IDataErrorInfo
    {
        ...
        ...
        public string Error
        {
            get
            {
                return ValidateAppointment();
            }
        }
 
        private string ValidateAppointment()
        {
            string errorString = this.ValidateResources();
 
            return errorString;
        }
 
        private string ValidateResources()
        {
            if(this.AppointmentResource.Count == 0)
            {
                return "Please choose at least one resource.";
            }
            return null;
        }
    }

Problem is that AppointmentResources.Count is always zero. It seems that checking a resource does not update the AppointmentResource entity collection. What am I doing wrong? How can I validate that resources are checked?

Regards
Neils

1 Answer, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 15 Oct 2012, 08:37 AM
Hello Neils,

You should use the Resources property when validating the resources in the CustomAppointment, the following code snippet shows how the validation should look like:
private string ValidateResource()
{
    if (this.Resources.Count == 0)
    {
        return "This appointment needs to have a resource!";
    }
    return null;
}

Note that if you want to alert the user to select a resource if none are selected you should create a custom EditAppointmentDialogStyle and add the needed fields to alert the user when the resource validation is not passed.

You can read this help article that goes through on how to customize the EditAppointmentDialogStyle.

Regards,
Vladi
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Asked by
Heiko
Top achievements
Rank 1
Veteran
Answers by
Vladi
Telerik team
Share this question
or