Esempio n. 1
0
        public void CorporateUploadDataRow(CorporateCustomerEditModel customerEditModel, IEnumerable <Language> languages, IEnumerable <Lab> labs,
                                           List <string> customTags, CorporateUploadEditModel corporateModel, IEnumerable <AccountAdditionalFieldsEditModel> accountAdditionalFields,
                                           List <EventCusomerAdjustOrderViewModel> adjustOrderForCustomerEditModel, OrganizationRoleUser createdByOrgRoleUser, long organizationRoleUserId,
                                           List <long> customerList, long?source, StringBuilder sb, long corporateUploadId, out CustomerWithDuplicateAcesModel customerIdWithSameAcesId)
        {
            var    customerWithSameAcesId = new CustomerWithDuplicateAcesModel();
            string errorMessage           = _corporateUploadHelper.CheckAddtionalField(customerEditModel, accountAdditionalFields);

            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new InvalidOperationException("System will not parse the customer data as " + errorMessage + " is not added for this corporate account.");
            }

            if (!string.IsNullOrEmpty(customerEditModel.PreApprovedPackage))
            {
                var preApprovedPackage = _packageRepository.GetByName(customerEditModel.PreApprovedPackage);
                if (preApprovedPackage == null)
                {
                    throw new InvalidOperationException("Package does not exist");
                }
                customerEditModel.PreApprovedPackageId = preApprovedPackage.Id;
            }

            //Customer customerWithAcesId = null;
            List <Customer> customersWithAcesId = null;

            var isMemberUploadByAces = false;

            isMemberUploadByAces = (source.HasValue && source.Value == (long)MemberUploadSource.Aces);

            if (!string.IsNullOrWhiteSpace(customerEditModel.AcesId))
            {
                customersWithAcesId = _customerRegistrationService.GetCustomersByAcesId(customerEditModel.AcesId);
                //if (!customersWithAcesId.IsNullOrEmpty() && customersWithAcesId.Count() > 1)
                //{
                //    throw new InvalidOperationException("Aces Id can not be duplicate, Aces Id : " + customerEditModel.AcesId + " already assigned.");
                //}

                //customerWithAcesId = customersWithAcesId.IsNullOrEmpty() ? null : customersWithAcesId.First();
            }

            if (customerEditModel.PreApprovedTest != null && customerEditModel.PreApprovedTest.Any())
            {
                var pairs = TestType.A1C.GetNameValuePairs();
                var preApprovedTestExists = pairs.Where(x => customerEditModel.PreApprovedTest.Contains(x.SecondValue.ToLower())).Select(x => x.SecondValue.ToLower());

                var testNotExist = string.Empty;

                if (preApprovedTestExists != null && preApprovedTestExists.Any() && (preApprovedTestExists.Count() != customerEditModel.PreApprovedTest.Count()))
                {
                    var testNotExistInSystem = customerEditModel.PreApprovedTest.Where(x => !preApprovedTestExists.Contains(x.ToLower())).Select(x => x).ToArray();

                    testNotExist = string.Join(",", testNotExistInSystem);
                }
                else if (preApprovedTestExists == null || !preApprovedTestExists.Any())
                {
                    testNotExist = string.Join(",", customerEditModel.PreApprovedTest);
                }

                if (!string.IsNullOrEmpty(testNotExist))
                {
                    throw new InvalidOperationException(testNotExist + " test alias name does not exist in HIP");
                }
            }

            if (string.IsNullOrEmpty(customerEditModel.Activity))
            {
                throw new InvalidOperationException("Activity cannot be blank.");
            }

            if (!isMemberUploadByAces && !(customerEditModel.Activity.ToLower() == UploadActivityType.MailOnly.GetDescription().ToLower() || customerEditModel.Activity.ToLower() == UploadActivityType.OnlyCall.GetDescription().ToLower() ||
                                           customerEditModel.Activity.ToLower() == UploadActivityType.BothMailAndCall.GetDescription().ToLower()))
            {
                throw new InvalidOperationException("Activity value invalid.");
            }

            if (isMemberUploadByAces && !(customerEditModel.Activity.ToLower() == UploadActivityType.MailOnly.GetDescription().ToLower() ||
                                          customerEditModel.Activity.ToLower() == UploadActivityType.None.GetDescription().ToLower() || customerEditModel.Activity.ToLower() == UploadActivityType.BothMailAndCall.GetDescription().ToLower() ||
                                          customerEditModel.Activity.ToLower() == UploadActivityType.DoNotCallDoNotMail.GetDescription().ToLower()))
            {
                throw new InvalidOperationException("Activity value invalid.");
            }

            if (!string.IsNullOrEmpty(customerEditModel.PredictedZip))
            {
                var invalidZipMessage = _customerRegistrationService.ValidateZipCodes(customerEditModel.PredictedZip);
                if (!string.IsNullOrEmpty(invalidZipMessage))
                {
                    throw new InvalidOperationException(invalidZipMessage);
                }
            }

            //if (string.IsNullOrEmpty(customerEditModel.TargetYear))
            //{
            //    throw new InvalidOperationException("Target Year is required");
            //}

            if (!string.IsNullOrEmpty(customerEditModel.TargetYear))
            {
                int targetYear;
                var validTargetYear = int.TryParse(customerEditModel.TargetYear, out targetYear);
                if (!validTargetYear || targetYear < DateTime.Now.Year || targetYear > (DateTime.Now.Year + 2))
                {
                    throw new InvalidOperationException("Invalid Target Year");
                }
            }

            if (!isMemberUploadByAces && !string.IsNullOrEmpty(customerEditModel.Email) && !IsValidEmailAddress(customerEditModel.Email))
            {
                throw new InvalidOperationException("Invalid Customer Email Address.");
            }

            if (!isMemberUploadByAces && !string.IsNullOrEmpty(customerEditModel.AlternateEmail) && !IsValidEmailAddress(customerEditModel.AlternateEmail))
            {
                throw new InvalidOperationException("Invalid Customer Alternate Email Address.");
            }

            if (!isMemberUploadByAces && !string.IsNullOrEmpty(customerEditModel.PcpEmail) && !IsValidEmailAddress(customerEditModel.PcpEmail))
            {
                throw new InvalidOperationException("Invalid PCP Email Address.");
            }

            if (!isMemberUploadByAces)
            {
                if ((!string.IsNullOrEmpty(customerEditModel.BillingMemberId) || !string.IsNullOrEmpty(customerEditModel.BillingMemberPlan)) && (customerEditModel.BillingMemberPlanYear == null || customerEditModel.BillingMemberPlanYear == 0))
                {
                    throw new InvalidOperationException("Billing Year is required");
                }

                if (customerEditModel.BillingMemberPlanYear.HasValue && customerEditModel.BillingMemberPlanYear.Value > 0 && string.IsNullOrEmpty(customerEditModel.BillingMemberId) && string.IsNullOrEmpty(customerEditModel.BillingMemberPlan))
                {
                    throw new InvalidOperationException("Billing MemberID or Billing Plan Name or both is required");
                }

                if (!string.IsNullOrEmpty(customerEditModel.WarmTransferAllowed) && (customerEditModel.WarmTransferAllowed.ToLower() != "yes" && customerEditModel.WarmTransferAllowed.ToLower() != "no"))
                {
                    throw new InvalidOperationException("Invalid WarmTransfer Allowed Value");
                }

                if (!string.IsNullOrEmpty(customerEditModel.WarmTransferAllowed) && string.IsNullOrEmpty(customerEditModel.WarmTransferYear))
                {
                    throw new InvalidOperationException("WarmTransfer Year is required");
                }
                if (!string.IsNullOrEmpty(customerEditModel.WarmTransferYear))
                {
                    int warmTransferYear;
                    var validWarmTransferYear = int.TryParse(customerEditModel.WarmTransferYear, out warmTransferYear);
                    if (!validWarmTransferYear || warmTransferYear < DateTime.Now.Year || warmTransferYear > (DateTime.Now.Year + 2))
                    {
                        throw new InvalidOperationException("Invalid WarmTransfer Year");
                    }
                }

                //if (customerEditModel.RequiredTest != null && customerEditModel.RequiredTest.Any())
                //{
                //    var pairs = TestType.A1C.GetNameValuePairs();
                //    var requiredTestExists = pairs.Where(x => customerEditModel.RequiredTest.Contains(x.SecondValue.ToLower())).Select(x => x.SecondValue.ToLower());

                //    var testNotExist = string.Empty;

                //    if (requiredTestExists != null && requiredTestExists.Any() && (requiredTestExists.Count() != customerEditModel.RequiredTest.Count()))
                //    {
                //        var testNotExistInSystem = customerEditModel.RequiredTest.Where(x => !requiredTestExists.Contains(x.ToLower())).Select(x => x).ToArray();

                //        testNotExist = string.Join(",", testNotExistInSystem);
                //    }
                //    else if (requiredTestExists == null || !requiredTestExists.Any())
                //    {
                //        testNotExist = string.Join(",", customerEditModel.RequiredTest);
                //    }

                //    if (!string.IsNullOrEmpty(testNotExist))
                //        throw new InvalidOperationException(testNotExist + " test alias name does not exist in HIP (Required Test)");

                //    if (string.IsNullOrEmpty(customerEditModel.ForYear))
                //    {
                //        throw new InvalidOperationException("For Year is required");
                //    }
                //    int forYear;
                //    var validforYear = int.TryParse(customerEditModel.ForYear, out forYear);
                //    if (!validforYear || forYear < DateTime.Now.Year || forYear > (DateTime.Now.Year + 2))
                //    {
                //        throw new InvalidOperationException("Invalid For Year");
                //    }
                //}
            }

            if (string.IsNullOrEmpty(customerEditModel.EligibilityYear))
            {
                throw new InvalidOperationException("Eligibility Year is required");
            }

            int eligibilityYear;
            var validEligibilityYear = int.TryParse(customerEditModel.EligibilityYear, out eligibilityYear);

            if (!validEligibilityYear || eligibilityYear < DateTime.Now.Year || eligibilityYear > (DateTime.Now.Year + 2))
            {
                throw new InvalidOperationException("Invalid Eligibility Year");
            }

            var activityPairs = UploadActivityType.MailOnly.GetNameValuePairs();
            var activityId    = activityPairs.First(x => customerEditModel.Activity.ToLower() == x.SecondValue.ToLower()).FirstValue;

            bool isNewCustomer = false;

            DateTime?dob = null;

            if (!string.IsNullOrEmpty(customerEditModel.Dob))
            {
                try
                {
                    dob = Convert.ToDateTime(customerEditModel.Dob);
                }
                catch (Exception ex)
                {
                    throw new Exception("DOB is not in correct format. Please Provide in MM/DD/YYYY", ex);
                }
            }

            if (isMemberUploadByAces)
            {
                if (string.IsNullOrEmpty(customerEditModel.Product))
                {
                    throw new InvalidOperationException("Product Type is required");
                }

                if (!string.IsNullOrEmpty(customerEditModel.Product))
                {
                    var productTypePairs = ProductType.CHA.GetNameValuePairs();

                    if (!productTypePairs.Any(x => x.SecondValue.ToLower() == customerEditModel.Product.ToLower()))
                    {
                        throw new InvalidOperationException("Invalid Product Type");
                    }
                }

                if (string.IsNullOrEmpty(customerEditModel.DNCFlag))
                {
                    throw new InvalidOperationException("DNC is required");
                }
                if (!string.IsNullOrEmpty(customerEditModel.DNCFlag))
                {
                    if (customerEditModel.DNCFlag.Trim() == "1")
                    {
                        customerEditModel.DNCFlag = "yes";
                    }
                    else if (customerEditModel.DNCFlag.Trim() == "0")
                    {
                        customerEditModel.DNCFlag = "no";
                    }
                    else
                    {
                        throw new InvalidOperationException("Invalid DNC, Only 0/1 is accepted.");
                    }
                }
            }
            var customer = _customerRepository.GetCustomerForCorporate(customerEditModel.FirstName, customerEditModel.MiddleName, customerEditModel.LastName,
                                                                       customerEditModel.Email, PhoneNumber.ToNumber(customerEditModel.PhoneHome), PhoneNumber.ToNumber(customerEditModel.PhoneCell),
                                                                       dob, corporateModel == null ? string.Empty : corporateModel.Tag, sb);

            if (customer == null && (sb != null && sb.ToString() != ""))
            {
                throw new Exception("");
            }
            else
            {
                sb = new StringBuilder();
            }

            //IEnumerable<EventCustomer> eventCustomers = null;

            //if (customer != null && customer.CustomerId > 0)
            //{
            //    eventCustomers = _eventCustomerPreApprovedTestService.GetFutureEventCustomers(customer.CustomerId);
            //}

            if (string.IsNullOrWhiteSpace(customerEditModel.State) || string.IsNullOrWhiteSpace(customerEditModel.City) || string.IsNullOrWhiteSpace(customerEditModel.Zip))
            {
                var addressErrorMessage = "";
                if (string.IsNullOrWhiteSpace(customerEditModel.State))
                {
                    addressErrorMessage = addressErrorMessage + "State";
                }

                if (string.IsNullOrWhiteSpace(customerEditModel.City))
                {
                    addressErrorMessage = string.IsNullOrWhiteSpace(addressErrorMessage) ? "City" : addressErrorMessage + ", City";
                }

                if (string.IsNullOrWhiteSpace(customerEditModel.Zip))
                {
                    addressErrorMessage = string.IsNullOrWhiteSpace(addressErrorMessage) ? "Zip" : addressErrorMessage + ", Zip";
                }

                addressErrorMessage = addressErrorMessage + " is required.";

                throw new Exception(addressErrorMessage);
            }

            AddressSanitizingInvalidZip(customerEditModel);

            if (customer != null && !customersWithAcesId.IsNullOrEmpty())
            {
                customersWithAcesId = customersWithAcesId.Where(x => x.CustomerId != customer.CustomerId).ToList();
            }

            if (!customersWithAcesId.IsNullOrEmpty())
            {
                customersWithAcesId.ForEach(x => x.AcesId = "");
            }

            using (var scope = new TransactionScope())
            {
                if (!customersWithAcesId.IsNullOrEmpty())
                {
                    foreach (var member in customersWithAcesId)
                    {
                        _customerService.SaveCustomerOnly(member, organizationRoleUserId);
                    }

                    customerWithSameAcesId.AcesId     = customerEditModel.AcesId;
                    customerWithSameAcesId.CustomerId = customer != null ? customer.CustomerId : 0;
                    customerWithSameAcesId.CustomersWithSameAcesId = string.Join(",", customersWithAcesId.Select(x => x.CustomerId));
                }

                var updatedCustomer = _customerRegistrationService.RegisterCorporateCustomer(customer, customerEditModel, corporateModel == null ? string.Empty : corporateModel.Tag,
                                                                                             createdByOrgRoleUser, languages, labs, sb, activityId, source, out isNewCustomer);

                if (customTags != null && customTags.Any() && updatedCustomer != null)
                {
                    foreach (var customTag in customTags)
                    {
                        _corporateCustomerCustomTagService.Save(new CorporateCustomerCustomTag
                        {
                            CustomerId           = updatedCustomer.CustomerId,
                            IsActive             = true,
                            Tag                  = customTag,
                            DataRecorderMetaData = new DataRecorderMetaData(new OrganizationRoleUser(organizationRoleUserId), DateTime.Now, null)
                        });
                    }
                }

                customerEditModel.CustomerId = updatedCustomer.CustomerId;

                //if (!eventCustomers.IsNullOrEmpty())
                //{
                //    var list = _eventCustomerPreApprovedTestService.MarkcustomerForAdjustOrder(customerEditModel, eventCustomers, createdByOrgRoleUser, updatedCustomer, corporateModel.UploadCorporateId);

                //    if (!list.IsNullOrEmpty())
                //        adjustOrderForCustomerEditModel = adjustOrderForCustomerEditModel.Concat(list).ToList();
                //}

                scope.Complete();
            }

            UpdateNeedVerificationAddress(customerEditModel);

            if (isNewCustomer && customerList != null)
            {
                customerList.Add(customerEditModel.CustomerId);
            }

            UpdateCorporateMemberUpload(corporateUploadId, customerEditModel);

            customerIdWithSameAcesId = customerWithSameAcesId;
        }
Esempio n. 2
0
        public void PollForOutboundChase()
        {
            var outboundUploads = _outboundUploadRepository.GetAllUploadedFilesByType((long)OutboundUploadType.ChaseOutbound);

            if (outboundUploads == null || !outboundUploads.Any())
            {
                _logger.Info("No new files uploaded.");
                return;
            }

            var accountIds = _accountIds.Split(',');

            //var activityTypes = _activityTypeRepository.GetAll();

            foreach (var accountId in accountIds)
            {
                var account = _corporateAccountRepository.GetById(Convert.ToInt32(accountId));

                var fileLocation         = _mediaRepository.GetOutboundUploadMediaFileLocation(account.FolderName, "Chase");
                var archivedFileLocation = _mediaRepository.GetOutboundUploadMediaFileLocation(account.FolderName, "ChaseArchived");

                foreach (var outboundUpload in outboundUploads)
                {
                    try
                    {
                        var file = GetFile(outboundUpload.FileId);

                        if (!System.IO.File.Exists(fileLocation.PhysicalPath + file.Path))
                        {
                            _logger.Info("File not found : " + fileLocation.PhysicalPath + file.Path);
                            continue;
                        }

                        _logger.Info("Importing File : " + file.Path);

                        outboundUpload.StatusId       = (long)OutboundUploadStatus.Parsing;
                        outboundUpload.ParseStartTime = DateTime.Now;
                        _outboundUploadRepository.Save(outboundUpload);

                        DataTable table = _pipeDelimitedReportHelper.Read(fileLocation.PhysicalPath + file.Path);

                        if (table.Rows.Count <= 0)
                        {
                            _logger.Info("No rows found.");
                            outboundUpload.ParseEndTime = DateTime.Now;
                            outboundUpload.StatusId     = (long)OutboundUploadStatus.Parsed;
                            _outboundUploadRepository.Save(outboundUpload);
                            continue;
                        }

                        var csvStringBuilder = new StringBuilder();
                        csvStringBuilder.Append(LogHeader + Environment.NewLine);

                        var languages = _languageRepository.GetAll();
                        var labs      = _labRepository.GetAll();

                        var successRows = 0;
                        foreach (DataRow row in table.Rows)
                        {
                            var model    = GetChaseOutboundModel(row);
                            var errorRow = model.TenantId + "|" + model.ClientId + "|" + model.CampaignId + "|" + model.IndividualId + "|" + model.ContractNumber + "|" + model.ContractPersonNumber + "|" + model.ConsumerId;
                            try
                            {
                                if (!string.IsNullOrEmpty(model.HomeAddressState))
                                {
                                    try
                                    {
                                        var state = _stateRepository.GetStatebyCode(model.HomeAddressState) ?? _stateRepository.GetState(model.HomeAddressState);
                                        if (state != null)
                                        {
                                            model.HomeAddressState = state.Name;
                                        }
                                        else
                                        {
                                            csvStringBuilder.Append(errorRow + "|" + "Invalid Home_Addr_State" + Environment.NewLine);
                                            continue;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.Error("Error importing data.");
                                        _logger.Error("Message: " + ex.Message + "\nStack Trace; " + ex.StackTrace);
                                        csvStringBuilder.Append(errorRow + "|" + ex.Message + Environment.NewLine);
                                        continue;
                                    }
                                }

                                if (!string.IsNullOrEmpty(model.AddressState))
                                {
                                    try
                                    {
                                        var state = _stateRepository.GetStatebyCode(model.AddressState) ?? _stateRepository.GetState(model.AddressState);
                                        if (state != null)
                                        {
                                            model.AddressState = state.Name;
                                        }
                                        else
                                        {
                                            csvStringBuilder.Append(errorRow + "|" + "Invalid Addr_State" + Environment.NewLine);
                                            continue;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.Error("Error importing data.");
                                        _logger.Error("Message: " + ex.Message + "\nStack Trace; " + ex.StackTrace);
                                        csvStringBuilder.Append(errorRow + "|" + ex.Message + Environment.NewLine);
                                        continue;
                                    }
                                }

                                if (!string.IsNullOrEmpty(model.ProviderOfRecordAddressState))
                                {
                                    try
                                    {
                                        var state = _stateRepository.GetStatebyCode(model.ProviderOfRecordAddressState) ?? _stateRepository.GetState(model.ProviderOfRecordAddressState);
                                        if (state != null)
                                        {
                                            model.ProviderOfRecordAddressState = state.Name;
                                        }
                                        else
                                        {
                                            csvStringBuilder.Append(errorRow + "|" + "Invalid Provider_Addr_State" + Environment.NewLine);
                                            continue;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.Error("Error importing data.");
                                        _logger.Error("Message: " + ex.Message + "\nStack Trace; " + ex.StackTrace);
                                        csvStringBuilder.Append(errorRow + "|" + ex.Message + Environment.NewLine);
                                        continue;
                                    }
                                }

                                var chaseOutbound = _chaseOutboundFactory.Create(model);

                                var corporateCustomerEditModel = _chaseOutboundFactory.CreateCorporateCustomerEditModel(model);

                                var           createdBy = _organizationRoleUserRepository.GetOrganizationRoleUser(1);
                                StringBuilder sb        = new StringBuilder();

                                //var activityType = activityTypes.FirstOrDefault(x => x.Alias == corporateCustomerEditModel.Activity);

                                bool     isNewCustomer = false;
                                DateTime?dob           = null;

                                if (!string.IsNullOrEmpty(corporateCustomerEditModel.Dob))
                                {
                                    try
                                    {
                                        dob = Convert.ToDateTime(corporateCustomerEditModel.Dob);
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("DOB is not in correct format. Please Provide in MM/DD/YYYY", ex);
                                    }
                                }

                                var customer = _customerRepository.GetCustomerForCorporate(corporateCustomerEditModel.FirstName, corporateCustomerEditModel.MiddleName,
                                                                                           corporateCustomerEditModel.LastName, corporateCustomerEditModel.Email, PhoneNumber.ToNumber(corporateCustomerEditModel.PhoneHome),
                                                                                           PhoneNumber.ToNumber(corporateCustomerEditModel.PhoneCell), dob, account.Tag, sb);

                                var updatedCustomer = _customerRegistrationService.RegisterCorporateCustomer(customer, corporateCustomerEditModel, account.Tag, createdBy, languages, labs,
                                                                                                             sb, (long)UploadActivityType.BothMailAndCall, null, out isNewCustomer);

                                chaseOutbound.CustomerId = updatedCustomer.CustomerId;

                                var address = new Address(model.AddressLine1, model.AddressLine2, model.AddressCity,
                                                          model.AddressState, model.AddressZipCode, "USA");


                                address = _addressService.SaveAfterSanitizing(address);
                                if (address.Id > 0)
                                {
                                    _customerRepository.UpdateBillingAddress(updatedCustomer.CustomerId, address.Id);
                                }
                                var customTags = model.CustomTags.Split(',');
                                if (customTags != null && customTags.Any() && updatedCustomer != null)
                                {
                                    foreach (var customTag in customTags)
                                    {
                                        _corporateCustomerCustomTagService.Save(new CorporateCustomerCustomTag
                                        {
                                            CustomerId           = updatedCustomer.CustomerId,
                                            IsActive             = true,
                                            Tag                  = customTag,
                                            DataRecorderMetaData = new DataRecorderMetaData(new OrganizationRoleUser(createdBy.Id), DateTime.Now, null)
                                        });
                                    }
                                }

                                if (!string.IsNullOrEmpty(model.RelationshipCode) || !string.IsNullOrEmpty(model.RelationshipDescription))
                                {
                                    var relationship = GetRelationship(model.RelationshipCode, model.RelationshipDescription);
                                    chaseOutbound.RelationshipId = relationship.Id;
                                }

                                chaseOutbound = _chaseOutboundRepository.Save(chaseOutbound);
                                // _chaseProductRepository.DeleteByCustomerId(chaseOutbound.CustomerId);

                                if (!string.IsNullOrEmpty(model.ProductLevel1))
                                {
                                    SaveChaseProduct(model.ProductLevel1, 1, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }
                                if (!string.IsNullOrEmpty(model.ProductLevel2))
                                {
                                    SaveChaseProduct(model.ProductLevel2, 2, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }
                                if (!string.IsNullOrEmpty(model.ProductLevel3))
                                {
                                    SaveChaseProduct(model.ProductLevel3, 3, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }
                                if (!string.IsNullOrEmpty(model.ProductLevel4))
                                {
                                    SaveChaseProduct(model.ProductLevel4, 4, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }
                                if (!string.IsNullOrEmpty(model.ProductLevel5))
                                {
                                    SaveChaseProduct(model.ProductLevel5, 5, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }

                                // _chaseChannelLevelRepository.DeleteByCustomerId(chaseOutbound.CustomerId);

                                if (!string.IsNullOrEmpty(model.ChannelLevel2))
                                {
                                    SaveChaseChannel(model.ChannelLevel2, 2, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }
                                if (!string.IsNullOrEmpty(model.ChannelLevel3))
                                {
                                    SaveChaseChannel(model.ChannelLevel3, 3, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }

                                if (!string.IsNullOrEmpty(model.GroupName) || !string.IsNullOrEmpty(model.GroupNumber) || !string.IsNullOrEmpty(model.GroupDivision))
                                {
                                    var chaseGroup = GetChaseGroup(model.GroupName, model.GroupNumber, model.GroupDivision);
                                    chaseOutbound.ChaseGroupId = chaseGroup.Id;
                                }

                                if (string.IsNullOrEmpty(model.CampaignId) || string.IsNullOrEmpty(model.CampaignName))
                                {
                                    _logger.Info("Campaign Id/Name missing. Incomplete Data");

                                    /*csvStringBuilder.Append(errorRow + "|" + "Campaign Id/Name missing. Incomplete Data." + Environment.NewLine);
                                     * continue;*/
                                }
                                else
                                {
                                    SaveCampaign(model, chaseOutbound.CustomerId, chaseOutbound.Id);
                                }

                                if (!string.IsNullOrEmpty(model.ForecastedOutreachDate))
                                {
                                    try
                                    {
                                        chaseOutbound.ForecastedOutreachDate = Convert.ToDateTime(model.ForecastedOutreachDate);
                                    }
                                    catch (Exception)
                                    {
                                        csvStringBuilder.Append(errorRow + "|" + "Forecasted_Outreach_Date is not in correct format. Please Provide in MM/DD/YYYY" + Environment.NewLine);
                                        continue;
                                    }
                                }
                                if (!string.IsNullOrEmpty(model.RecordProcessDate))
                                {
                                    try
                                    {
                                        chaseOutbound.RecordProcessDate = Convert.ToDateTime(model.RecordProcessDate);
                                    }
                                    catch (Exception)
                                    {
                                        csvStringBuilder.Append(errorRow + "|" + "Record_Process_Date is not in correct format. Please Provide in MM/DD/YYYY" + Environment.NewLine);
                                        continue;
                                    }
                                }



                                successRows++;
                            }
                            catch (Exception ex)
                            {
                                _logger.Error("Error importing data.");
                                _logger.Error("Message: " + ex.Message + "\nStack Trace; " + ex.StackTrace);
                                csvStringBuilder.Append(errorRow + "|" + ex.Message + Environment.NewLine);
                            }
                        }

                        if (successRows < table.Rows.Count)
                        {
                            var logFileName = _pipeDelimitedReportHelper.GetReportName(ReportType.Exception);

                            var logFile = SaveLogFile(fileLocation.PhysicalPath + logFileName + ".txt", csvStringBuilder);
                            outboundUpload.LogFileId = logFile.Id;
                        }

                        outboundUpload.SuccessUploadCount = successRows;
                        outboundUpload.FailedUploadCount  = table.Rows.Count - successRows;
                        outboundUpload.ParseEndTime       = DateTime.Now;
                        outboundUpload.StatusId           = successRows > 0 ? (long)OutboundUploadStatus.Parsed : (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(outboundUpload);

                        if (successRows > 1)
                        {
                            System.IO.File.Move(fileLocation.PhysicalPath + file.Path, archivedFileLocation.PhysicalPath + file.Path);
                            ((IFileRepository)_fileRepository).MarkasArchived(file.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        outboundUpload.StatusId = (long)OutboundUploadStatus.ParseFailed;
                        _outboundUploadRepository.Save(outboundUpload);
                        _logger.Error(string.Format("while Parsing File"));
                        _logger.Error("Ex Message" + ex.Message);
                        _logger.Error("Ex Stack Trace " + ex.StackTrace);
                    }
                }
            }
        }