Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public void SetValidatorMessage(string propertyName, string message)
 {
     ValidatorMessages.Add(new ErrorMessage {
         PropertyName = propertyName, Message = message
     });
     Status = ResponseState.Warning;
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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"));
            }
Esempio n. 6
0
        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"));
            }
Esempio n. 7
0
        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"));
            }
Esempio n. 8
0
        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"));
            }
Esempio n. 9
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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"));
            }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
 private string InvalidValueMessage(string fieldName = null)
 {
     return(ValidatorMessages.InvalidTimeValueMessage(fieldName));
 }
Esempio n. 15
0
 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));
Esempio n. 16
0
 private string EmptyValueMessage(string fieldName = null)
 {
     return(ValidatorMessages.EmptyValueMessage(fieldName));
 }
Esempio n. 17
0
 private string NotExistsInDatabase(string fieldName = null)
 {
     return(ValidatorMessages.NotExistsInDatabase(fieldName));
 }
Esempio n. 18
0
 private string GreaterThan(string oppositeField, string fieldName = null)
 {
     return(ValidatorMessages.ShouldBeGreaterThan(oppositeField, fieldName));
 }