public RowValidatorModel RowValidator(TransactionRowModel row, TransactionSummaryModel summaryEntity)
        {
            var results   = new List <ValidationResult>();
            var context   = new ValidationContext(row);
            var sb        = new StringBuilder();
            var validator = new RowValidatorModel
            {
                IsValid      = false,
                FailureModel = null
            };

            if (!Validator.TryValidateObject(row, context, results, true))
            {
                foreach (var error in results)
                {
                    sb.AppendFormat("{0} |", error.ErrorMessage);
                }
                validator.FailureModel                      = new ValidationFailureModel();
                validator.IsValid                           = false;
                validator.FailureModel.RowNumber            = row.RowNumber;
                validator.FailureModel.TransactionSummaryId = summaryEntity.Id;
                validator.FailureModel.Error                = sb.ToString();
            }
            else
            {
                validator.IsValid      = true;
                validator.FailureModel = null;
            }

            return(validator);
        }
Exemple #2
0
        private TransactionSummaryModel CreateSumary()
        {
            var summaryEntity = new TransactionSummaryModel {
                Id = new Guid()
            };

            uploadRepository.CreateTransactionSummary(summaryEntity);
            return(summaryEntity);
        }
Exemple #3
0
        private TransactionSummaryModel SummaryFilling(TransactionSummaryModel summaryEntity)
        {
            var failureList  = uploadRepository.GetFailuresBySummary(summaryEntity.Id);
            var transactList = uploadRepository.GetTransactionsBySummary(summaryEntity.Id);

            summaryEntity.FailureRow = failureList.Count;
            summaryEntity.SuccessRow = transactList.Count;
            uploadRepository.Commit();
            return(summaryEntity);
        }
Exemple #4
0
        private TransactionModel GetTransaction(TransactionRowModel row, TransactionSummaryModel summaryEntity)
        {
            var entity = new TransactionModel();

            entity.SenderAccountNumber    = row.SenderAccountNumber;
            entity.RecipientAccountNumber = row.RecipientAccountNumber;
            entity.Summ                 = row.Summ;
            entity.TransactionDate      = row.TransactionDate;
            entity.Description          = row.Description;
            entity.TransactionSummaryId = summaryEntity.Id;
            return(entity);
        }
        public void ValidationRowTest()
        {
            validationService = new ValidationTransactService();
            TransactionRowModel row = new TransactionRowModel
            {
                SenderAccountNumber    = "2554255635588473",
                RecipientAccountNumber = "2568785964823541",
                Summ            = Double.MaxValue,
                TransactionDate = DateTime.Now
            };
            TransactionSummaryModel summaryModel = new TransactionSummaryModel();

            var result = validationService.RowValidator(row, summaryModel).IsValid;

            Assert.IsTrue(result);
        }
 public void CreateTransactionSummary(TransactionSummaryModel summary)
 {
     context.Summarys.Add(summary);
     context.SaveChanges();
 }