public static void OnInit(ClientErrorManager manager, IValidatingService validatingService) { manager.AddErrors(new ClientErrors("Validating", new Dictionary <string, ClientError> { { "v-func-no", new ClientError("No validation function to property!") }, { "v-dto-invalid", new ClientError("Invalid dto!") } })); validatingService.AddValidateFunc("not-null", (object prop, PropValidateContext context) => { if (prop == null) { context.Valid.Add($"Please input {context.PropName}!"); } }); validatingService.AddValidateFunc("str-input", (string prop, PropValidateContext context) => { if (string.IsNullOrEmpty(prop)) { context.Valid.Add($"Please input {context.PropName}!"); } }); }
public static void OnInit(IValidatingService validatingService) { validatingService.AddValidateFunc("str-reason", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (prop.Length > 300) { context.Valid.Add($"[str-too-long, [pn-{context.PropName}], 300]");// $"Please input {context.PropName}!" } }); }
public static void OnInit(IValidatingService validating) { validating.AddValidateFunc("name", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (prop.Length > 40) { context.Valid.Add($"Too long name, maximum 40 characters!"); } if (prop.Length < 1) { context.Valid.Add($"Too short name!"); } if (!Regex.Match(prop, "^[a-zA-Z_0-9]*$").Success) { context.Valid.Add($"Name musn't have specials chars!"); } }); validating.AddValidateFunc("stats", (string stats, PropValidateContext context) => { if (stats == null) { return; } if (!Int32.TryParse(stats, out var m) || m < 1) { context.Valid.Add($"Incorrect stats!"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService) { manager.AddErrors(new ClientErrors("DirectMessagesService", new Dictionary <string, ClientError>() { { "inc-chatid", new ClientError("Incorrect chat!") }, { "inc-message-id", new ClientError("Incorrect message id!") } })); validatingService.AddValidateFunc("dr-text-message", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (prop.Length < 1 || prop.Length > 300) { context.Valid.Add($"[dr-text-message-inc-length, [pn-{context.PropName}]]"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, SubjectServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("PupilSubject", new Dictionary <string, ClientError> { { "u-inc-subject-id", new ClientError("Incorrect subject id!") } })); validatingService.AddValidateFunc("str-sb-name", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsName) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {255}]"); } /*if (prop.Length < configuration.MinCountCharsName) * ctx.Valid.Add($"[str-too-short, [pn-{ctx.PropName}], {255}]"); * if (!Regex.Match(prop, "^[ а-яА-ЯҐґЄєІіЇї]+$").Success) * ctx.Valid.Add($"[str-no-spc-ch-2, [pn-{ctx.PropName}]]"); //"Name musn't have specials chars!"*/ }); validatingService.AddValidateFunc("str-sb-comment", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsComment) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {255}]"); } /*if (!Regex.Match(prop, "^[ а-яА-ЯҐґЄєІіЇї]+$").Success) * ctx.Valid.Add($"[str-no-spc-ch-2, [pn-{ctx.PropName}]]"); //"Comment musn't have specials chars!"*/ }); validatingService.AddValidateFunc("number-day-sb", (string prop, PropValidateContext ctx) => { int value; if (prop == null || !Int32.TryParse(prop, out value)) { return; } if (value > configuration.MaxDayNumber || value < configuration.MinDayNumber) { ctx.Valid.Add($"[inc-number-day]"); } }); validatingService.AddValidateFunc("number-lesson-sb", (string prop, PropValidateContext ctx) => { int value; if (prop == null || !Int32.TryParse(prop, out value)) { return; } if (value > configuration.MaxLessonNumber || value < configuration.MinLessonNumber) { ctx.Valid.Add($"[inc-number-lesson]"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, RegistrationServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("Login", new Dictionary <string, ClientError>() { { "l-user-banned", new ClientError("User banned!") }, { "l-pass-log-inc", new ClientError("Incorrect login or password!") }, { "l-too-many-devices", new ClientError("Too many devices logged!") } })); validatingService.AddValidateFunc("date-birthday", (DateTime? prop, PropValidateContext context) => { if (prop == null) { return; } if (prop.Value == null || prop.Value > DateTime.Now) { context.Valid.Add($"[r-date-birthday-incorrect]"); } }); validatingService.AddValidateFunc("str-email-reg-no", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (context.SeriviceProvider.GetService <IUserService>().IsIssetByEmail(prop)) { context.Valid.Add($"[r-email-reg]"); // "User with this email is already registered!" } }); validatingService.AddValidateFunc("str-login", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsLogin) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxCountCharsLogin}]"); // "Too long login(max {_configuration.MaxCountCharsLogin} characters)!" } if (!Regex.Match(prop, "^[a-zA-Z_0-9]*$").Success) { ctx.Valid.Add($"[str-no-spc-ch, [pn-{ctx.PropName}]]"); // "Login musn't have specials chars!" } }); validatingService.AddValidateFunc("str-creds", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsName) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {255}]"); } if (!Regex.Match(prop, "^[а-яА-ЯҐґЄєІіЇї]+$").Success) { ctx.Valid.Add($"[str-no-spc-ch-2, [pn-{ctx.PropName}]]"); //"Name musn't have specials chars!" } }); validatingService.AddValidateFunc("str-password", (string prop, PropValidateContext ctx) => { if (prop == null) { return; } if (prop.Length > configuration.MaxCountCharsPassword) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxCountCharsPassword}]");//$"Too long password(max{} characters)!" } if (prop.Length < configuration.MinCountCharsPassword) { ctx.Valid.Add($"[str-too-sh, [pn-{ctx.PropName}], {configuration.MaxCountCharsPassword}]");//$"Password must have {_configuration.MinCountCharsPassword} and more chars! } if (!prop.Any(c => char.IsDigit(c))) { ctx.Valid.Add($"[str-no-dig, [pn-{ctx.PropName}]]");//$"Password must have minimum one digit!" } }); validatingService.AddValidateFunc("str-password-rep", (string prop, PropValidateContext ctx) => { if (prop == null || ctx.TypeDto.GetProperty("Password") == null || ctx.TypeDto.GetProperty("Password").GetValue(ctx.Dto) == null) { return; } if (prop != (string)ctx.TypeDto.GetProperty("Password").GetValue(ctx.Dto)) { ctx.Valid.Add($"[str-inc-rep, [pn-{ctx.PropName}]]"); //$"Incorrect repeat password!" } }); validatingService.AddValidateFunc("str-email", (string prop, PropValidateContext context) => { if (prop == null) { return; } if (!Regex.IsMatch(prop, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$")) { context.Valid.Add($"[v-str-email, [pn-{context.PropName}]]"); } }); }
public static void OnInit(ClientErrorManager manager, IValidatingService validatingService, LanguageStringServiceConfiguration configuration) { manager.AddErrors(new ClientErrors("LanguageStringService", new Dictionary <string, ClientError> { { "lss-inc-lang-str", new ClientError("Incorrect language string!") }, { "lss-lng-ald-reg", new ClientError("Language already registered!") }, { "lss-lng-no-reg", new ClientError("Incorrect language!") }, { "lss-type-ald-reg", new ClientError("Type already registered!") }, { "lss-type-no-reg", new ClientError("Incorrect type!") }, { "lss-strid-ald-reg", new ClientError("String id already registered!") }, { "lss-strid-no-reg", new ClientError("Incorrect string id!") }, { "lss-baseupateid-inc", new ClientError("Incorrect base update id!") } })); validatingService.AddValidateFunc("lss-lng-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length != 2) { ctx.Valid.Add($"[lss-inc-lang-str]"); } }); validatingService.AddValidateFunc("lss-lng-type", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxTypeNameLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxTypeNameLength}]"); //"Too long login(max {_configuration.MaxCountCharsLogin} characters)!" } }); validatingService.AddValidateFunc("lss-str-id-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxStringIdNameLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxStringIdNameLength}]"); } }); validatingService.AddValidateFunc("lss-str-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxStringLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxStringLength}]"); } }); validatingService.AddValidateFunc("lss-lng-full-name", (string som, PropValidateContext ctx) => { if (som == null) { return; } else if (som.Length > configuration.MaxLangFullNameLength) { ctx.Valid.Add($"[str-too-long, [pn-{ctx.PropName}], {configuration.MaxLangFullNameLength}]"); } }); }