protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (value == null) { return(ValidationResult.Success); } if (!IsCollection) { if (!IsValidExtension(value as IFormFile)) { return(new ValidationResult(ValidatorMessages.FileExtensionsValidatorMessage(extensions))); } } else { var files = value as List <IFormFile>; foreach (var file in files) { if (!IsValidExtension(file)) { return(new ValidationResult(ValidatorMessages.FileExtensionsValidatorMessage(extensions))); } } } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { if (!isCollection) { var file = value as IFormFile; if (file != null && file.Length > maxFileSize * Constants.UnitConversionMultiplier * Constants.UnitConversionMultiplier) { return(new ValidationResult(ValidatorMessages.MaxFileSizeValidatorMessage(maxFileSize))); } } else { var files = value as List <IFormFile>; if (files != null) { foreach (var file in files) { if (file.Length > maxFileSize * Constants.UnitConversionMultiplier * Constants.UnitConversionMultiplier) { return(new ValidationResult(ValidatorMessages.MaxFileSizeValidatorMessage(maxFileSize))); } } } } return(ValidationResult.Success); }
public void SetValidatorMessage(string propertyName, string message) { ValidatorMessages.Add(new ErrorMessage { PropertyName = propertyName, Message = message }); Status = ResponseState.Warning; }
public bool ValidateImagesForMember(int userId, IEnumerable <ReportImage> reportImages, IEnumerable <IFormFile> images) { int imagesCount = 0; long userReportImagesSize = 0; reportImages.Where(ri => ri.UserId == userId).ToList() .ForEach(ri => (imagesCount, userReportImagesSize) = (imagesCount + 1, userReportImagesSize + ri.Size)); foreach (var image in images) { if (userReportImagesSize + image.Length <= Constants.MaximumReportImagesSizePerUser) { imagesCount += (int)Math.Ceiling(image.Length / (decimal)Constants.MaximumReportImageSize); } else { return(false); } if (imagesCount > Constants.MaximumReportImagesCountPerUser) { throw new UploadFileException( ValidatorMessages.MaxFilesCountValidatorMessage(Constants.MaximumReportImagesCountPerUser)); } } return(true); }
public async Task <ResultModel> Remove(int paymentId, int userId) { var result = new ResultModel(); var payment = await _paymentRepository.GetById(paymentId); if (payment is null || payment.UserId != userId) { result.AddNotification(ValidatorMessages.NotFound("Pagamento")); }
public async Task <ResultModel> Remove(int id, int userId) { var result = new ResultModel(); var householdExpense = await _householdExpenseRepository.GetById(id); if (householdExpense is null || householdExpense.UserId != userId) { result.AddNotification(ValidatorMessages.NotFound("Despesa Doméstica")); }
public async Task <ResultModel> Remove(int id, int userId) { var result = new ResultModel(); var recurringExpense = await _recurringExpenseRepository.GetById(id); if (recurringExpense is null || recurringExpense.UserId != userId) { result.AddNotification(ValidatorMessages.NotFound("Despesa Recorrente")); }
public async Task <ResultModel> Delete(int id, int userId) { var result = new ResultModel(); var vehicle = await _vehicleRepository.GetById(id); if (vehicle is null || vehicle.UserId != userId) { result.AddNotification(ValidatorMessages.NotFound("Veículo")); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var files = value as List <IFormFile>; if (files?.Count > maxFilesCount) { return(new ValidationResult(ValidatorMessages.MaxFilesCountValidatorMessage(maxFilesCount))); } return(ValidationResult.Success); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { string str = (string)value; if (str != null && str.Any(c => charactersNotAllowed.Contains(c))) { return(new ValidationResult(ValidatorMessages.CharactersValidatorMessage(charactersNotAllowed))); } return(ValidationResult.Success); }
public async Task <ResultModel> Update(int userId, RemainingBalanceModel model) { var result = new ResultModel(); var remainingBalance = await _remainingBalanceRepository.GetByMonthYear(userId, new DateTime(model.Year, model.Month, 1)); if (remainingBalance == null) { result.AddNotification(ValidatorMessages.NotFound("Saldo Remanecente")); return(result); } remainingBalance.Value = model.Value; await _remainingBalanceRepository.Update(remainingBalance); return(result); }
public async Task <ResultModel> Remove(int id, int userId) { var result = new ResultModel(); var fuelExpenses = await _fuelExpensesRepository.GetById(id); if (fuelExpenses is null) { result.AddNotification(ValidatorMessages.NotFound("Despesa de Combustível")); return(result); } var vehicle = await _vehicleRepository.GetById(fuelExpenses.VehicleId); if (vehicle is null || vehicle.UserId != userId) { result.AddNotification(ValidatorMessages.NotFound("Despesa de Combustível")); }
public async Task <ResultModel> Remove(int id, int userId) { var result = new ResultModel(); var card = (await _creditCardRepository.GetSome(new BaseFilter() { UserId = userId })).FirstOrDefault(p => p.Id == id); if (card is null) { result.AddNotification(ValidatorMessages.NotFound("Cartão de Crédito")); return(result); } if (_creditCardRepository.HasPayments(id).Result) { result.AddNotification(ValidatorMessages.CreditCard.BindedWithPayments); return(result); } await _creditCardRepository.Remove(id); return(result); }
private string InvalidValueMessage(string fieldName = null) { return(ValidatorMessages.InvalidTimeValueMessage(fieldName)); }
public static IRuleBuilderOptions <T, TElement> MaxFilesCountIs <T, TElement>(this IRuleBuilderOptions <T, TElement> ruleBuilder, int maxFilesCount) => ruleBuilder.Must(files => (files as List <IFormFile>) == null ? true : (files as List <IFormFile>).Count <= maxFilesCount).WithMessage(ValidatorMessages.MaxFilesCountValidatorMessage(maxFilesCount));
private string EmptyValueMessage(string fieldName = null) { return(ValidatorMessages.EmptyValueMessage(fieldName)); }
private string NotExistsInDatabase(string fieldName = null) { return(ValidatorMessages.NotExistsInDatabase(fieldName)); }
private string GreaterThan(string oppositeField, string fieldName = null) { return(ValidatorMessages.ShouldBeGreaterThan(oppositeField, fieldName)); }