public JsonResult UploadCustomers(UploadCorporateCustomers model)
        {
            var fileName          = model.FileName;
            var pageSize          = model.PageSize;
            var tag               = model.Tag;
            var failedRecordsFile = model.FailedRecordsFile;
            var adjustOrderFile   = model.AdjustOrderRecordsFile;
            var pageNumber        = model.PageNumber;
            var customTags        = model.CustomTags;

            if (customTags != null)
            {
                customTags = customTags.Where(s => !string.IsNullOrEmpty(s)).Select(s => s).ToList();
            }
            var corporateModel = new CorporateUploadEditModel {
                Tag = tag, FileName = fileName, UploadCorporateId = model.UploadCorporateId
            };

            var mediaLocation = _mediaRepository.GetUploadCsvMediaFileLocation();
            var file          = mediaLocation.PhysicalPath + corporateModel.FileName;

            var csvReader = IoC.Resolve <ICsvReader>();

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

            var failureRecords         = mediaLocation.PhysicalPath + failedRecordsFile;
            var adjustOrderRecordsFile = mediaLocation.PhysicalPath + model.AdjustOrderRecordsFile;

            var customerTable        = csvReader.ReadWithTextQualifier(file);
            var createdByOrgRoleUser = Mapper.Map <OrganizationRoleUserModel, OrganizationRoleUser>(_sessionContext.UserSession.CurrentOrganizationRole);

            var customerIdWithSameAcesId = new List <CustomerWithDuplicateAcesModel>();

            try
            {
                //var failedCustomers = new List<CorporateCustomerEditModel>();
                var adjustOrderForCustomerEditModel = new List <EventCusomerAdjustOrderViewModel>();

                var query = customerTable.AsEnumerable();

                var rows                    = query.Skip(pageSize * (pageNumber - 1)).Take(pageSize);
                var customerToRender        = rows.Count();
                var corporateAccount        = _corporateAccountRepository.GetByTag(tag);
                var accountAdditionalFields = _accountAdditionalFieldRepository.GetAccountAdditionalFieldsEditModelByAccountId(corporateAccount.Id);
                var customerEditModel       = new CorporateCustomerEditModel();

                foreach (DataRow row in rows)
                {
                    var sb = new StringBuilder();
                    try
                    {
                        customerEditModel = _corporateUploadHelper.GetCorporateCustomerEditModel(row);

                        var customerWithDuplicateAcesModel = new CustomerWithDuplicateAcesModel();
                        _corporateUploadService.CorporateUploadDataRow(customerEditModel, languages, labs, customTags, corporateModel,
                                                                       accountAdditionalFields, adjustOrderForCustomerEditModel, createdByOrgRoleUser,
                                                                       _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId, null,
                                                                       (long)MemberUploadSource.CorporateUplaod, sb, model.UploadCorporateId.Value, out customerWithDuplicateAcesModel);

                        if (customerWithDuplicateAcesModel != null && customerWithDuplicateAcesModel.CustomerId > 0)
                        {
                            customerIdWithSameAcesId.Add(customerWithDuplicateAcesModel);
                        }
                    }
                    catch (Exception ex)
                    {
                        customerEditModel.ErrorMessage = sb.ToString();
                        if (!string.IsNullOrEmpty(ex.Message))
                        {
                            customerEditModel.ErrorMessage += " Error Message: " + ex.Message;
                        }
                        //failedCustomers.Add(customerEditModel);
                    }

                    var memberUploadParseDetail = _memberUploadParseDetailFactory.GetDomain(customerEditModel, model.UploadCorporateId.Value);
                    _memberUploadParseDetailRepository.Save(memberUploadParseDetail);
                }

                if (!customerIdWithSameAcesId.IsNullOrEmpty())
                {
                    _customerWithDuplicateAcesIdFileGenerator.GenerateCsvFile(model.UploadCorporateId.Value, customerIdWithSameAcesId);
                }

                corporateModel.TotalCustomers = customerTable.Rows.Count;

                var totalPages      = corporateModel.TotalCustomers / pageSize + (corporateModel.TotalCustomers % pageSize != 0 ? 1 : 0);
                var failedCustomers = _memberUploadParseDetailRepository.GetByCorporateUploadId(model.UploadCorporateId.Value, false);
                corporateModel.FailedCustomers = failedCustomers != null?failedCustomers.Count() : 0;

                corporateModel.UploadedCustomers = customerToRender - corporateModel.FailedCustomers;
                corporateModel.IsParseSucceded   = totalPages == pageNumber;

                if (corporateModel.IsParseSucceded)
                {
                    var corporateUploadedBy = _sessionContext.UserSession.FullName;

                    string corporateName = string.Empty;
                    if (corporateAccount != null)
                    {
                        var organization = _organizationRepository.GetOrganizationbyId(corporateAccount.Id);
                        if (organization != null)
                        {
                            corporateName = organization.Name;
                        }
                    }

                    var corporateUploadNotificationModel = _emailNotificationModelsFactory.GetCorporateUploadNotificationViewModel(corporateName, corporateUploadedBy, corporateModel.TotalCustomers, (corporateModel.TotalCustomers - corporateModel.FailedCustomers), corporateModel.FailedCustomers);

                    _notifier.NotifySubscribersViaEmail(NotificationTypeAlias.CorporateUploadNotification, EmailTemplateAlias.CorporateUploadNotification, corporateUploadNotificationModel, 0, 1, "System: Corporate Upload Notification");
                    _logger.Info("Corporate Upload Notification:Mail Send for upload corporate :" + tag + " UploadedBy:  " + corporateUploadedBy + " on : " + DateTime.Now);
                }

                corporateModel.FailedRecordsFile = failedRecordsFile;

                if (failedCustomers != null && failedCustomers.Any())
                {
                    var failedMember = _memberUploadParseDetailFactory.GetCorporateCustomerListModel(failedCustomers, model.UploadCorporateId.Value);
                    _corporateUploadHelper.UpdateFailedRecords(failureRecords, failedMember);

                    if (model.LogFileId < 1)
                    {
                        var fileInfo = new FileInfo(failureRecords);

                        var files = new Core.Application.Domain.File
                        {
                            Path       = fileInfo.Name,
                            FileSize   = fileInfo.Length,
                            Type       = FileType.Csv,
                            UploadedBy = new OrganizationRoleUser(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId),
                            UploadedOn = DateTime.Now
                        };

                        files = _fileRepository.Save(files);

                        model.LogFileId = files.Id;
                    }
                }

                if (adjustOrderForCustomerEditModel.Any())
                {
                    _corporateUploadHelper.UpdateAdjustOrderRecords(adjustOrderRecordsFile, adjustOrderForCustomerEditModel);
                    if (model.AdjustOrderLogFileId < 1)
                    {
                        var fileInfo = new FileInfo(adjustOrderRecordsFile);
                        var files    = new Core.Application.Domain.File
                        {
                            Path       = fileInfo.Name,
                            FileSize   = fileInfo.Length,
                            Type       = FileType.Csv,
                            UploadedBy = new OrganizationRoleUser(_sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId),
                            UploadedOn = DateTime.Now
                        };

                        files = _fileRepository.Save(files);

                        model.AdjustOrderLogFileId = files.Id;
                    }
                }

                if (model.UploadCorporateId.HasValue && corporateModel.IsParseSucceded)
                {
                    var count = _corporateUploadHelper.FailedCustomerCount(failedRecordsFile, mediaLocation);

                    var uploadCorporate = _corporateUploadRepository.GetById(model.UploadCorporateId.Value);
                    uploadCorporate.SuccessfullUploadCount = (corporateModel.TotalCustomers - count);
                    uploadCorporate.FailedUploadCount      = count;

                    if (model.LogFileId > 0)
                    {
                        uploadCorporate.LogFileId = model.LogFileId;
                    }

                    if (model.AdjustOrderLogFileId > 0)
                    {
                        uploadCorporate.AdjustOrderLogFileId = model.AdjustOrderLogFileId;
                    }

                    uploadCorporate.ParseStatus = (int)MemberUploadParseStatus.Start;
                    _corporateUploadRepository.Save(uploadCorporate);
                }

                corporateModel.FailedCustomersListPath = _corporateUploadHelper.CheckIsFileContainsRecord(corporateModel.IsParseSucceded, mediaLocation, failedRecordsFile);
                corporateModel.AdjustOrderRecordsFile  = _corporateUploadHelper.CheckIsFileContainsRecord(corporateModel.IsParseSucceded, mediaLocation, adjustOrderFile);
            }
            catch (Exception ex)
            {
                corporateModel.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage(ex.Message);
            }

            return(Json(new
            {
                corporateModel.FileName,
                corporateModel.UploadedCustomers,
                corporateModel.Tag,
                corporateModel.FailedCustomers,
                corporateModel.IsParseSucceded,
                PageNumber = pageNumber + 1,
                corporateModel.FailedCustomersListPath,
                LogFileId = model.LogFileId,
                corporateModel.AdjustOrderRecordsFile,
                model.AdjustOrderLogFileId
            }, JsonRequestBehavior.AllowGet));
        }