public ContactFormValidator(ILocalizationWebApi localizationWebApi, IWorkContext workContext) { var languageId = _workContext.Current.WorkingLanguageId; RuleFor(x => x.EmailTo).NotEmpty().WithMessage(localizationWebApi.GetResource("Section.ContactForm.EmailTo.Required", languageId).GetAwaiter().GetResult()); RuleFor(x => x.EmailTo).EmailAddress().WithMessage(localizationWebApi.GetResource("Common.WrongEmail", languageId).GetAwaiter().GetResult()); RuleFor(x => x.Subject).NotEmpty().WithMessage(localizationWebApi.GetResource("Section.ContactForm.Subject.Required", languageId).GetAwaiter().GetResult()); _workContext = workContext; }
public ContactFormReadOnlyValidator(ILocalizationWebApi localizationWebApi, IWorkContext workContext) { var languageId = _workContext.Current.WorkingLanguageId; RuleFor(x => x.Name).NotNull() .WithMessage(localizationWebApi.GetResource("Section.ContactForm.Name.Required", languageId).GetAwaiter().GetResult()) .When(x => x.NameEnabled); RuleFor(x => x.EmailFrom).NotEmpty().WithMessage(localizationWebApi.GetResource("Section.ContactForm.EmailFrom.Required", languageId).GetAwaiter().GetResult()); RuleFor(x => x.EmailFrom).EmailAddress().WithMessage(localizationWebApi.GetResource("Common.WrongEmail", languageId).GetAwaiter().GetResult()); RuleFor(x => x.Message).NotEmpty().WithMessage(localizationWebApi.GetResource("Section.ContactForm.Message.Required", languageId).GetAwaiter().GetResult()); _workContext = workContext; //http://www.beabigrockstar.com/using-fluent-validation-with-asp-net-mvc-part-4-database-validation/ //Custom(s => // { // var model = (ContactForm)sectionService.GetById(s.Id); // if(model.ShowName) // RuleFor(x => x.Name).NotEmpty().WithMessage(localizationService.GetResource("Section.ContactForm.Name.Required")).; // return null; // }); }
private void InsertExperienceRow(Experience exp, Table table, string resourceKey, Text value, float leading = 0) { //var cell = new Cell(); //cell.SetBorder(Border.NO_BORDER); var resourceValue = _localizationWebApi.GetResource(resourceKey).GetAwaiter().GetResult(); Cell cell = InsertColumn(new Text(resourceValue), leading); table.AddCell(cell); Cell cellValue = InsertColumn(value, leading); table.AddCell(cellValue); }