c# - "Complex validation" with INotifyDataErrorInfo and MVVM (MVVMLight) -


basically problem want perform validation against values form database (ef) before execute bl. i'm using inotifydataerrorinfo attributes in properties of viewmodel. tried validation custom validator (customvalidation attribute):

        private string unit;         [required(allowemptystrings = false, errormessage = constants.error6)]         [regularexpression(constants.alphabeticregex, errormessage = constants.error10)]         [customvalidation(typeof(productselectionviewmodel),"isinregisteredunits")]         public string unit         {             { return unit; }             set             {                 if (value == unit)                     return;                 unit = value;                 raisepropertychanged(vm => vm.unit);                 updateunitprice(selectedproduct, unit);             }         } 

but method in charge of performing validation must static one, under scenario cannot acces repository since not static.

        public static validationresult isinregisteredunits(object obj, validationcontext context)         {             var productselectionviewmodel = (productselectionviewmodel)context.objectinstance;              if (!unitservice.getallunitsabbreviation().any(x=>x.equals(productselectionviewmodel.unit, stringcomparison.currentcultureignorecase)))                 return new validationresult("la unidad ingresada no es vĂ¡lida", new list<string> { "unit" });             return validationresult.success;         } 

how can solve (unitservice.getallunitsabbreviation() cannot static method since using repository), maybe i'm performing kind of validation in worng place (wrong design), appreciated :)


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -