Ejemplo n.º 1
0
 private void ValidateExcelForFields(ref CampaignValidation validations, List<string> fields, IQueryable<Row> excelRows)
 {
     foreach (var field in fields)
     {
         try
         {
             var chkField = excelRows.First()[field];
         }
         catch (Exception ex)
         {
             validations.Messages.Add(new CampaignValidationMessage(field, CampaignError.FieldMissing, 0));
             validations.IsValid = false;
         }
     }
 }
Ejemplo n.º 2
0
        public CampaignReport ValidateCampaign(CampaignVM campaignVM)
        {
            CampaignValidation validations = new CampaignValidation();
            var fileName = campaignVM.FileName;
            var fields = GetAllMappingFields(campaignVM.Content);
            fields.AddRange(GetAllMappingFields(campaignVM.RecipientField));
            if (campaignVM.TypeId == (int)CampaignType.Email)
                fields.AddRange(GetAllMappingFields(campaignVM.Subject));

            var excelRows = GetExcelMappings(fileName);
            ValidateExcelForFields(ref validations, fields, excelRows);

            var validRows = new List<Row>();
            if (validations.IsValid)
            {
                int rowCount = 2;
                foreach (var row in excelRows)
                {
                    var recepient = row[GetAllMappingFields(campaignVM.RecipientField)[0]];
                    if (validations.Validate(recepient, (CampaignType)campaignVM.TypeId, rowCount))
                        validRows.Add(row);
                    rowCount += 1;
                }

            }
            validations.TotalRecordCount = excelRows.Count();
            var report = new CampaignReport
            {
                Campaign = campaignVM,
                ExcelRows = validRows,
                Validations = validations
            };
            return report;
        }