Example #1
0
 private void OnClientFileImportListAdd(ClientFileImport entity)
 {
     SendPropertyChanging(null);
     entity.Client = this;
     SendPropertyChanged(null);
 }
Example #2
0
 private void OnClientFileImportListRemove(ClientFileImport entity)
 {
     SendPropertyChanging(null);
     entity.Client = null;
     SendPropertyChanged(null);
 }
Example #3
0
        public XmlImportInfo TransformToXml(CsvFileInfo csvFileInfo, List<FieldMap> fieldMaps)
        {

            string csvFilePath = csvFileInfo.Path;
            var rawRows = GetRawRows(csvFilePath).Skip(csvFileInfo.FirstRowContainsColumnHeadings ? 1 : 0);
            var category = _xmlRepository.GetCategory(csvFileInfo.Category);
            var flag = _xmlRepository.GetFlag(csvFileInfo.Flag);

            var rowsToContacts = ConvertRowsToContacts(rawRows, fieldMaps, category, flag);

            var xmlFilePath = csvFilePath.Replace(Path.GetExtension(csvFilePath), ".xml");
            XmlImportInfo importResult = null;
            try
            {
                GenerateXml(rowsToContacts.Contacts, xmlFilePath);
                using (DomainContext ctx = new DomainContext())
                {
                    var account = System.Web.HttpContext.Current.Session["allClientsAccountModel"] as AllClientsAccountModel;
                    var importRecord = new ClientFileImport();
                    importRecord.Id = Guid.NewGuid();
                    importRecord.ImportedFilePath = xmlFilePath;
                    importRecord.UploadFilePath = csvFileInfo.Path;
                    importRecord.RecordsImported = rowsToContacts.SuccessCount;
                    importRecord.RecordsFailed = rowsToContacts.FailureCount;
                    importRecord.ClientId = account.ClientId;
                    importRecord.LastUpdated = System.DateTime.Now;
                    ctx.ClientFileImport.InsertOnSubmit(importRecord);
                    ctx.SubmitChanges();
                }
                var importFile = new FileInfo(xmlFilePath);
                importResult = new XmlImportInfo { SuccessCount = rowsToContacts.SuccessCount, FailureCount = rowsToContacts.FailureCount, DuplicateCount = rowsToContacts.DuplicateCount, FileName = Path.GetFileName(xmlFilePath) };
                ImportWorkflow(importFile, importResult);
            }
            catch (Exception e)
            {
                throw e;
            }
            return importResult;
        }