Note that there are some explanatory texts on larger screens.

plurals
  1. POCasting Object depending on its type
    primarykey
    data
    text
    <p>I made a validation method for business rules that are not verified from my rules in the model, but I'm having a problem to make it work. Since there are two possible scenarios(customer or seller registration), they need to be treated separately in their own views and models. The seller registration inherits from customer registration for the basic info, so all fields in customer are also in seller. But since I'm working with 2 different models, even though both have the same fields that I'm doing the validation upon, I needed to use <code>Object</code> to use the same validation method. But unfortunately I'm having trouble to do so.</p> <pre><code>[CustomHandleError] private bool ValidateRegistrationForm (Object registerViewModelObject) { if (registerViewModelObject is RegisterViewModel) { RegisterViewModel registerViewModel = (RegisterViewModel)registerViewModelObject; } else { RegisterSellerViewModel registerViewModel = (RegisterSellerViewModel)registerViewModelObject; } if (ModelState.IsValid) { string [] names = registerViewModel.Name.Split ( new string [] {" "}, StringSplitOptions.RemoveEmptyEntries); if (names.Length == 1) ModelState.AddModelError ("Name", "Fill your full name"); if (CustomerUtilities.IsCpf (registerViewModel.Identity) == false) ModelState.AddModelError ("Identity", "Invalid CPF value"); if (this.AuthenticatorService.IsExistentUser (registerViewModel.Email)) ModelState.AddModelError ("Email", "Email already registered"); } } </code></pre> <p>As you can see, after the <code>if (ModelState.IsValid)</code> the IntelliSense doesn't find registerViewModel in the current context. I wonder why this happens, since that variable is defined inside the if AND the else above, so there is no way to reach that code without it being defined. </p> <p>Is there any workaround for this(other than creating a new method or passing 2 variables)?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload