Exemple #1
0
        private bool ParseMemberUploadbyAces(string file, CorporateAccount corporateAccount, List <long> customerList, IEnumerable <Language> languages, IEnumerable <Lab> labs)
        {
            try
            {
                _logger.Info("Start converting data from CSV to data table :" + DateTime.Now);

                var mediaLocation = _mediaRepository.GetMemberUploadbyAcesFolderLocation();
                var fileToParse   = GetFileName(file, mediaLocation);
                var memberData    = GetRows(fileToParse);

                var corportateUpload = _memberUploadByAcesHelper.Upload(fileToParse, corporateAccount);

                if (memberData == null)
                {
                    return(false);
                }

                var rowCountInFile = memberData.Rows.Count;

                _logger.Info("Data coverted from CSV to Data Table :" + DateTime.Now + " & Row count is : " + rowCountInFile);

                if (IsAnyColumnMissing(memberData))
                {
                    return(false);
                }

                //var failedCustomers = new List<MemberUploadbyAcesFailedCustomerModel>();
                var adjustOrderCustomer = new List <EventCusomerAdjustOrderViewModel>();

                var rows = memberData.AsEnumerable();

                var orgRoleUser = new OrganizationRoleUser()
                {
                    Id = OrgRoleUserId, RoleId = OrgRoleId
                };
                var corporateModel = new CorporateUploadEditModel {
                    Tag = corporateAccount.Tag, CorporateAccountId = corporateAccount.Id, UploadCorporateId = corportateUpload.Id
                };

                var accountAdditionalFields = _accountAdditionalFieldRepository.GetAccountAdditionalFieldsEditModelByAccountId(corporateAccount.Id);
                var index = 1;
                var customerIdWithSameAcesId = new List <CustomerWithDuplicateAcesModel>();

                foreach (DataRow row in rows)
                {
                    _logger.Info(index + " out of " + rowCountInFile + " processing");

                    var customerEditModel = CreateEditModel(row);

                    if (customerEditModel == null)
                    {
                        continue;
                    }
                    var sb = new StringBuilder();

                    try
                    {
                        _logger.Info("Record:  First Name :" + customerEditModel.FirstName + ", Last Name :" + customerEditModel.LastName + " and ACES Id :" + customerEditModel.AcesId);
                        var customerWithDuplicateAcesModel = new CustomerWithDuplicateAcesModel();
                        _corporateUploadService.CorporateUploadDataRow(customerEditModel, languages, labs, null, corporateModel, accountAdditionalFields,
                                                                       adjustOrderCustomer, orgRoleUser, OrgRoleId, customerList, (long)MemberUploadSource.Aces, sb, corportateUpload.Id, 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;
                        }
                        _logger.Error("While Saving customer");
                        _logger.Error(customerEditModel.ErrorMessage);
                        //var model = _memberUploadbyAcesFailedCustomerFactory.Create(customerEditModel);
                        //failedCustomers.Add(model);
                    }
                    _logger.Info(index + " out of " + rowCountInFile + " completed");

                    var memberUploadParseDetail = _memberUploadParseDetailFactory.GetDomain(customerEditModel, corportateUpload.Id);
                    _memberUploadParseDetailRepository.Save(memberUploadParseDetail);

                    index++;
                }

                if (!customerIdWithSameAcesId.IsNullOrEmpty())
                {
                    _customerWithDuplicateAcesIdFileGenerator.GenerateCsvFile(corportateUpload.Id, customerIdWithSameAcesId);
                }

                var failedRecords   = _memberUploadParseDetailRepository.GetByCorporateUploadId(corportateUpload.Id, false);
                var failedCustomers = _memberUploadParseDetailFactory.GetMemberUploadbyAcesFailedCustomerListModel(failedRecords, corportateUpload.SourceId);

                CreateFailedUploadFile(file, mediaLocation, failedCustomers, corportateUpload);

                CreateAdjustOrderUploadFile(file, mediaLocation, adjustOrderCustomer, corportateUpload);

                corportateUpload.ParseStatus = (int)MemberUploadParseStatus.Start;
                corportateUpload             = _memberUploadByAcesHelper.UpdateCorporateUpload(corportateUpload, failedCustomers.Count(), rowCountInFile);

                if (corportateUpload.SuccessfullUploadCount > 0)
                {
                    _logger.Info("Set IsTermByAbsence is True");
                    corportateUpload.IsTermByAbsence = true;
                    _corporateUploadRepository.Save(corportateUpload);

                    _logger.Info("Publishing: Corporate Upload Id: " + corportateUpload.Id);
                    _memberTermByAbsencePublisher.PublishCorporateUpload(corportateUpload.Id);
                    _logger.Info("Publish Successfully: Corporate Upload Id: " + corportateUpload.Id);
                }

                return(failedCustomers.Any() || accountAdditionalFields.Any() || customerList.Any());
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Error occurred while processing the {0}.\nMessage: {1}\n\tStackTrace: {2}", file, ex.Message, ex.StackTrace));
                return(false);
            }
        }
 public CorporateUpload SaveCorporateUpload(CorporateUpload corporateUpload)
 {
     return(_corporateUploadRepository.Save(corporateUpload));
 }
Exemple #3
0
 private void UpdateCorporateUploadStatus(CorporateUpload corporateUpload, MemberUploadParseStatus status)
 {
     corporateUpload.ParseStatus = (int)status;
     _corporateUploadRepository.Save(corporateUpload);
     _logger.Info("Updated CorporateUpload Status to " + status.ToString());
 }
        public ActionResult CorporateUpload(CorporateUploadEditModel model, HttpPostedFileBase corporateUploadFile)
        {
            if (Request.Files.Count < 1 || corporateUploadFile == null)
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("No file has been uploaded. Please upload a csv file.");
                return(View(model));
            }

            var uploadMediaLocation = _mediaRepository.GetUploadCsvMediaFileLocation();
            var account             = ((IUniqueItemRepository <CorporateAccount>)_corporateAccountRepository).GetById(model.CorporateAccountId);
            var organization        = _organizationRepository.GetOrganizationbyId(model.CorporateAccountId);

            model.Tag  = account.Tag;
            model.Name = organization.Name;
            model.UploadCsvMediaUrl = _mediaRepository.GetSamplesLocation().Url;


            HttpPostedFileBase file = Request.Files[0];
            var physicalPath        = uploadMediaLocation.PhysicalPath;
            var fileUploadedName    = (Path.GetFileNameWithoutExtension(file.FileName) + Path.GetExtension(file.FileName)).Replace("'", "").Replace("&", "");

            var fileName = (Path.GetFileNameWithoutExtension(fileUploadedName) + "_" + DateTime.Now.ToString("MMddyyyyhhmmss") + Path.GetExtension(fileUploadedName)).Replace("'", "").Replace("&", "");

            var fullPath = physicalPath + fileName;

            file.SaveAs(fullPath);

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

            if (customerTable.Rows.Count == 0)
            {
                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Uploaded file has no data.");
                return(View(model));
            }

            var columns            = customerTable.Columns.Cast <DataColumn>().Select(x => x.ColumnName.ToLower()).ToArray();
            var missingColumnNames = _corporateUploadHelper.CheckAllColumnExist(columns);

            if (!string.IsNullOrEmpty(missingColumnNames))
            {
                model.FeedbackMessage =
                    FeedbackMessageModel.CreateFailureMessage("Missing Column Name(s) : " + missingColumnNames);

                return(View(model));
            }

            var disabledTags = _corporateTagService.DisabledTagsInUsed(model.CustomTags, model.CorporateAccountId);

            if (disabledTags != null && disabledTags.Any())
            {
                model.CustomTags = model.CustomTags.Where(x => disabledTags.Contains(x)).ToList();

                model.FeedbackMessage = FeedbackMessageModel.CreateFailureMessage("Following tag(s) has been deactivated: " + string.Join(",", disabledTags));

                return(View(model));
            }

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

            files = _fileRepository.Save(files);

            var corporateUpload = new CorporateUpload
            {
                FileId     = files.Id,
                UploadTime = DateTime.Now,
                UploadedBy = _sessionContext.UserSession.CurrentOrganizationRole.OrganizationRoleUserId,
                AccountId  = model.CorporateAccountId,
                SourceId   = (long)MemberUploadSource.CorporateUplaod
            };

            corporateUpload = _corporateUploadRepository.Save(corporateUpload);

            model.TotalCustomers   = customerTable.Rows.Count;
            model.IsUploadSucceded = true;
            model.IsParseSucceded  = false;
            model.FileName         = fileName;

            var failedFileName = Path.GetFileNameWithoutExtension(fileUploadedName).Replace("+", "_");

            model.FailedRecordsFile = failedFileName + "_Failure_" + DateTime.Now.ToString("MMddyyyyhhmmss") + ".csv";

            if (corporateUpload != null && corporateUpload.Id > 0)
            {
                model.UploadCorporateId = corporateUpload.Id;
            }

            var failureRecords = uploadMediaLocation.PhysicalPath + model.FailedRecordsFile;

            _corporateUploadHelper.CreateHeaderFileRecord(failureRecords, customerTable);


            model.AdjustOrderRecordsFile = failedFileName + "_AdjustOrder_" + DateTime.Now.ToString("MMddyyyyhhmmss") + ".csv";
            var adjustOrderRecordsFile = uploadMediaLocation.PhysicalPath + model.AdjustOrderRecordsFile;

            _corporateUploadHelper.CreateHeaderAdjustOrderForEventCustoerRecord(adjustOrderRecordsFile);

            return(View(model));
        }