#19772: Fixed e-mail activity form validation.

Work Item: 19772
This commit is contained in:
Piotr Szmyd
2013-09-29 22:57:08 +02:00
parent c1ad9f7869
commit 77e5657f26

View File

@@ -82,23 +82,25 @@ namespace Orchard.Email.Forms {
}
public void Validating(ValidatingContext context) {
if (context.FormName == "ActionEmail") {
if (context.ValueProvider.GetValue("Recipient").AttemptedValue == String.Empty) {
context.ModelState.AddModelError("Recipient", T("You must select at least one recipient").Text);
}
if (context.FormName != "ActivityActionEmail") return;
if (context.ValueProvider.GetValue("Subject").AttemptedValue == String.Empty) {
context.ModelState.AddModelError("Subject", T("You must provide a Subject").Text);
}
var recipientFormValue = context.ValueProvider.GetValue("Recipient");
var recipient = recipientFormValue != null ? recipientFormValue.AttemptedValue : String.Empty;
if (context.ValueProvider.GetValue("Body").AttemptedValue == String.Empty) {
context.ModelState.AddModelError("Body", T("You must provide a Body").Text);
}
if (recipient == String.Empty) {
context.ModelState.AddModelError("Recipient", T("You must select at least one recipient").Text);
}
if (context.ValueProvider.GetValue("RecipientOther").AttemptedValue == String.Empty &&
context.ValueProvider.GetValue("Recipient").AttemptedValue == "other") {
context.ModelState.AddModelError("Recipient", T("You must provide an e-mail address").Text);
}
if (context.ValueProvider.GetValue("Subject").AttemptedValue == String.Empty) {
context.ModelState.AddModelError("Subject", T("You must provide a Subject").Text);
}
if (context.ValueProvider.GetValue("Body").AttemptedValue == String.Empty) {
context.ModelState.AddModelError("Body", T("You must provide a Body").Text);
}
if (context.ValueProvider.GetValue("RecipientOther").AttemptedValue == String.Empty && recipient == "other") {
context.ModelState.AddModelError("RecipientOther", T("You must provide an e-mail address").Text);
}
}