Beispiel #1
0
        public int GetExpectedIncome(long tin)
        {
            IRepository <Client> clientRepository  = new ClientRepository();
            ImportRepository     importsRepository = new ImportRepository();

            var client  = clientRepository.FindById(tin);
            var imports = importsRepository.FindByClientId(tin);

            int discount = client.Discount;

            int expectedIncome = 0;

            foreach (var i in imports)
            {
                if (i.IsStored)
                {
                    var elapsed = i.DepartureDate.Subtract(i.EntryDate);
                    int days    = Convert.ToInt32(elapsed.TotalDays);
                    int income  = 2 * i.PriceByUnit / (100 - discount);
                    income          = income * days;
                    expectedIncome += income;
                }
            }

            return(expectedIncome);
        }
Beispiel #2
0
 public ActionResult NewHomePage()
 {
     using (var iRepository = new ImportRepository())
     {
         return(View(iRepository.GetHomePageContent()));
     }
 }
Beispiel #3
0
        private void SaveData <T>(int logId, IEnumerable <T> importList) where T : IImportEntity
        {
            using var sha1 = new SHA1Managed();
            var dataList = new List <ImportData>();

            foreach (var item in importList)
            {
                var jsonData   = item.ToJsonData();
                var checkSum   = sha1.ComputeHash(Encoding.UTF8.GetBytes(jsonData)).ToHexString();
                var dataExists = ImportRepository.GetLatestData(rootsmagicSourceId, item.ItemType, item.ItemId);

                if (dataExists?.CheckSum == checkSum)
                {
                    continue;
                }

                dataList.Add(new ImportData
                {
                    LogId      = logId,
                    ItemTypeId = item.ItemType,
                    ItemId     = item.ItemId,
                    Data       = jsonData,
                    CheckSum   = checkSum,
                });
            }

            var insertedRows = ImportRepository.AddData(dataList);

            Logger.LogInformation("Importing {0}... {1}", typeof(T).Name, insertedRows);
        }
Beispiel #4
0
        public async static Task <dynamic> Import(string user)
        {
            ImportRepository _importRepository = new ImportRepository();

            try
            {
                /*
                 * List<Formula> formulas = await _importRepository.Formulas(user);
                 * List<Detalle> detalles = await _importRepository.Detalles(user);
                 * List<Cliente> clientes = await _importRepository.Clientes(user);
                 * List<Articulo> articulos = await _importRepository.Articulos();
                 *
                 * await _importRepository.Guardar(clientes);
                 * await _importRepository.Guardar(formulas);
                 * await _importRepository.Guardar(detalles);
                 *
                 * return new
                 * {
                 *  formulas = formulas,
                 *  detalles = detalles,
                 *  clientes = clientes
                 * };
                 */
                var res = await _importRepository.PullChanges_Articulos();

                return(res);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #5
0
 public ActionResult LeadTimes()
 {
     using (var iRepo = new ImportRepository())
     {
         return(View(iRepo.GetLeadTimeSummary()));
     }
 }
Beispiel #6
0
 public ActionResult EditLeadTimes()
 {
     using (var iRepo = new ImportRepository())
     {
         return(View(iRepo.GetLeadTimeInformation()));
     }
 }
Beispiel #7
0
        public ActionResult SearchLog()
        {
            using (var iRepo = new ImportRepository())
            {
                var logList = iRepo.GetSearchLogList();

                return(View(logList));
            }
        }
Beispiel #8
0
        public ActionResult RebuildDBKeywords()
        {
            using (var iRepo = new ImportRepository())
            {
                iRepo.RebuildDBKeywords();

                return(RedirectToAction("Index"));
            }
        }
Beispiel #9
0
 public ImportService(string connectionString, string ftpAddress, string login, string password, string downloadPath, string csvSeparator)
 {
     ImportRepository = new ImportRepository(connectionString);
     FtpAddress       = ftpAddress;
     Login            = login;
     Password         = password;
     DownloadPath     = downloadPath;
     CsvSeparator     = csvSeparator;
 }
Beispiel #10
0
        public List <UserImport> LoadUserImports(string userId)
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                return(new List <UserImport>());
            }

            return(ImportRepository.LoadUserImports(userId));
        }
Beispiel #11
0
        public CreateImportTests(ImportRepository repository)
        {
            _repository = repository;
            var import = new ImportResult { Date = DateTime.Now, ImportType = "", Name = "Import", };
            var transaction = new Transaction { Date = new DateTime(2010, 1, 1), Amount = 100, Reference = "ABCD", Description = "Transaction" };
            transaction.Credit.Add(new Amount(TestData.Bank, EntryType.Credit, 100));
            transaction.Debit.Add(new Amount(TestData.Expenses, EntryType.Debit, 100));

            var transactions = new[] { transaction };
            _repository.Save(import, transactions);
        }
Beispiel #12
0
 public JsonpResult LogSearchResults(string searchText, int seriesCount, int imageCount, int typicalCount, int pageCount)
 {
     using (ImportRepository iRepo = new ImportRepository())
     {
         return(new JsonpResult()
         {
             Data = iRepo.LogSearchResults(searchText, seriesCount, imageCount, typicalCount, pageCount),
             JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
 }
Beispiel #13
0
        public static string GetHomePageContentHTML()
        {
            using (var iRepo = new ImportRepository())
            {
                var contentArea = iRepo.GetHomePageContent();
                if (contentArea != null)
                {
                    return(contentArea.ContentArea);
                }
            }

            return("");
        }
Beispiel #14
0
        public ActionResult NewHomePage(HomePageContentInformation content)
        {
            if (ModelState.IsValid)
            {
                using (var iRepo = new ImportRepository())
                {
                    iRepo.UpsertHomePageContent(content);

                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View());
        }
Beispiel #15
0
        public ActionResult EditLeadTimes(LeadTimeInformation info)
        {
            if (ModelState.IsValid)
            {
                using (var iRepo = new ImportRepository())
                {
                    iRepo.UpdateLeadTimes(info);
                }

                return(RedirectToAction("LeadTimes"));
            }

            return(View(info));
        }
Beispiel #16
0
        public static bool MakeFiles()
        {
            IRepository <Client>  clientRepository  = new ClientRepository();
            IRepository <Import>  importRepository  = new ImportRepository();
            IRepository <Product> productRepository = new ProductRepository();
            IRepository <User>    userRepository    = new UserRepository();

            var clientsList  = clientRepository.FindAll();
            var importsList  = importRepository.FindAll();
            var productsList = productRepository.FindAll();
            var usersList    = userRepository.FindAll();

            return(makeClienstFile(clientsList) &&
                   makeImportsFile(importsList) &&
                   makeProductsFile(productsList) &&
                   makeUsersFile(usersList));
        }
        public bool AddImport(string productId, long tin, int priceByUnit,
                              int ammount, bool IsStored, DateTime entryDate, DateTime departureDate)
        {
            Product product = new Product(productId);
            Client  client  = new Client(tin);

            IRepository <Import> repository = new ImportRepository();
            Import import = new Import(product, client, ammount, priceByUnit, entryDate, departureDate, IsStored);

            if (repository.Add(import))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #18
0
        public AnalyticsCardInfoVm GetCardInfo(long masterAccountId, long ftpCredId)
        {
            var result  = new AnalyticsCardInfoVm();
            var dateNow = DateTime.UtcNow.AddDays(-1);

            var importedQuery = ImportRepository.ImportedFilesQuery();
            var zohoQuery     = ImportRepository.FileUploadQuery().Include(f => f.ImportedFile);

            if (masterAccountId != 0)
            {
                importedQuery = importedQuery.Where(f => f.MasterAccountId == masterAccountId);
                zohoQuery     = zohoQuery.Where(f => f.ImportedFile.MasterAccountId == masterAccountId);
            }

            if (ftpCredId != 0)
            {
                importedQuery = importedQuery.Where(f => f.FtpCredentialId == ftpCredId);
                zohoQuery     = zohoQuery.Where(f => f.ImportedFile.FtpCredentialId == ftpCredId);
            }

            result.RegisteredFiles = importedQuery.Count(f => f.RegisteredDate != null &&
                                                         DbFunctions.TruncateTime(f.FileCreateDate) ==
                                                         DbFunctions.TruncateTime(dateNow));
            result.ImportedFiles = importedQuery.Count(f => f.ImportedDate != null &&
                                                       DbFunctions.TruncateTime(f.FileCreateDate) ==
                                                       DbFunctions.TruncateTime(dateNow));

            result.ZohoFiles = zohoQuery.Count(f => DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) ==
                                               DbFunctions.TruncateTime(dateNow));

            result.SentFiles = zohoQuery.Count(f => f.IsSent &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) ==
                                               DbFunctions.TruncateTime(dateNow));

            result.LastSeenFtpJob    = SyncerInfoService.GetLastSeen("FtpJob");
            result.LastSeenCopyJob   = SyncerInfoService.GetLastSeen("CopyFromFtpJob");
            result.LastSeenImportJob = SyncerInfoService.GetLastSeen("ImportJob");
            result.LastSeenZohoJob   = SyncerInfoService.GetLastSeen("FileDeliveryJob");

            return(result);
        }
Beispiel #19
0
        private static bool makeImportsTable()
        {
            string folder   = "Files";
            string fileName = "Imports.txt";

            string route = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, folder, fileName);

            try
            {
                StreamReader file = new StreamReader(route);
                string       line = file.ReadLine();

                List <Import> importList = new List <Import>();

                while (line != null)
                {
                    string[] values = line.Split('#');

                    Product product = new Product(values[0]);
                    Client  client  = new Client(Convert.ToInt64(values[1]));

                    Import import = new Import(product, client, Convert.ToInt32(values[2]), Convert.ToInt32(values[3]), Convert.ToDateTime(values[4]), Convert.ToDateTime(values[5]), Convert.ToBoolean(values[6]));
                    importList.Add(import);

                    line = file.ReadLine();
                }

                IRepository <Import> importRepository = new ImportRepository();

                foreach (var i in importList)
                {
                    importRepository.Add(i);
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Beispiel #20
0
        public void Import()
        {
            Logger.LogInformation("Starting import");
            var stopwatch = Stopwatch.StartNew();

            // Get Import Source
            var source = ImportRepository.GetSource(rootsmagicSourceId);

            // Get Source Type
            //var sourceType = ImportRep.GetSourceType(source.SourceTypeId);

            // Create log
            var logId = ImportRepository.AddLog(new ImportLog
            {
                SourceId = source.Id,
                Imported = DateTime.UtcNow,
                Status   = 0,
            });

            SaveData(logId, RootsMagic.GetChildren());
            SaveData(logId, RootsMagic.GetCitations());
            SaveData(logId, RootsMagic.GetEvents());
            SaveData(logId, RootsMagic.GetFactTypes());
            SaveData(logId, RootsMagic.GetFamilies());
            SaveData(logId, RootsMagic.GetMediaLinks());
            SaveData(logId, RootsMagic.GetMultimedia());
            SaveData(logId, RootsMagic.GetNames());
            SaveData(logId, RootsMagic.GetPersons());
            SaveData(logId, RootsMagic.GetPlaces());
            SaveData(logId, RootsMagic.GetRoles());
            SaveData(logId, RootsMagic.GetSources());
            SaveData(logId, RootsMagic.GetSourceTemplates());
            SaveData(logId, RootsMagic.GetUrls());
            SaveData(logId, RootsMagic.GetWitnesses());

            stopwatch.Stop();
            Logger.LogInformation("Elapsed time: {0}", stopwatch.Elapsed.ToString(@"mm\:ss\.fff"));
        }
        public async Task BuildImports()
        {
            var securityRepository = new SecurityRepository("http://127.0.0.1:5984");
            var securityResult     = await securityRepository.GetAll();

            var securities       = securityResult.GetData <List <Models.Security> >();
            var importRepository = new ImportRepository("http://127.0.0.1:5984");

            foreach (var security in securities)
            {
                var import = new Import
                {
                    Symbol    = security.Symbol,
                    Type      = "broker-transactions",
                    CreatedBy = "iamstupendous"
                };
                var json = JsonConvert.SerializeObject(import, new IsoDateTimeConverter {
                    DateTimeFormat = Models.Constants.DateFormat
                });
                var postResponse = await importRepository.Documents.PostAsync(json);
            }
            Assert.IsTrue(true);
        }
Beispiel #22
0
        public ActionResult Index(HttpPostedFileBase csvFile)
        {
            if (ModelState.IsValid)
            {
                if (csvFile != null)
                {
                    using (var iRepo = new ImportRepository())
                    {
                        iRepo.ImportFileData(csvFile.InputStream, csvFile.ContentLength);

                        ViewBag.ImportSuccess = true;

                        return(View());
                    }
                }
                else
                {
                    ModelState.AddModelError("", "PDW file is required to upload new data.");
                }
            }

            return(View());
        }
Beispiel #23
0
        public ChartDataVm GetChartData(AnalyticsChartDataParams @params)
        {
            var result = new ChartDataVm();

            var impQuery = ImportRepository.ImportedFilesQuery();
            var delQuery = ImportRepository.FileUploadQuery().Include(f => f.ImportedFile);

            if (@params.MasterAccountId != 0)
            {
                impQuery = impQuery.Where(f => f.MasterAccountId == @params.MasterAccountId);
                delQuery = delQuery.Where(f => f.ImportedFile.MasterAccountId == @params.MasterAccountId);
            }

            if (@params.FtpCredentialId != 0)
            {
                impQuery = impQuery.Where(f => f.FtpCredentialId == @params.FtpCredentialId);
                delQuery = delQuery.Where(f => f.ImportedFile.FtpCredentialId == @params.FtpCredentialId);
            }

            var srcFilesData = new ChartDataVm.DataSet {
                Label = "Source files"
            };
            var impFilesData = new ChartDataVm.DataSet {
                Label = "Imported files"
            };
            var delFilesData = new ChartDataVm.DataSet {
                Label = "ZOHO files"
            };
            var sentFilesData = new ChartDataVm.DataSet {
                Label = "Sent ZOHO files"
            };

            var periods = @params.Periods.ToPeriodList().ToList();

            periods.ToList().ForEach(period =>
            {
                var srcFiles = impQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate));

                var impFiles = impQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.FileCreateDate) >= DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate) &&
                                              f.ImportedDate != null);

                var delFiles = delQuery.Count(f =>
                                              DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >=
                                              DbFunctions.TruncateTime(period.FromDate) &&
                                              DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <= DbFunctions.TruncateTime(period.ToDate));

                var sentFiles = delQuery.Count(f => f.IsSent &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) >=
                                               DbFunctions.TruncateTime(period.FromDate) &&
                                               DbFunctions.TruncateTime(f.ImportedFile.FileCreateDate) <=
                                               DbFunctions.TruncateTime(period.ToDate));

                srcFilesData.Data.Add(srcFiles);
                impFilesData.Data.Add(impFiles);
                delFilesData.Data.Add(delFiles);
                sentFilesData.Data.Add(sentFiles);
            });

            result.Data   = new[] { srcFilesData, impFilesData, delFilesData, sentFilesData };
            result.Labels = TradeUtils.GetPeriodLabels(periods).ToArray();

            return(result);
        }
Beispiel #24
0
 public List <ImportHeader> LoadImportHeadersById(List <int> headerIds)
 {
     return(ImportRepository.LoadImportHeadersById(headerIds));
 }
Beispiel #25
0
 public List <ImportData> LoadDataByImportId(long importId)
 {
     return(ImportRepository.LoadDataByImportId(importId));
 }
Beispiel #26
0
 public List <ImportData> LoadDataByImportId(List <long> importIds)
 {
     return(ImportRepository.LoadDataByImportId(importIds));
 }
Beispiel #27
0
 public List <ImportParameter> LoadParametersByImportId(long importId)
 {
     return(ImportRepository.LoadParametersByImportId(importId));
 }
Beispiel #28
0
 public List <ImportHeader> LoadImportHeadersByImportId(long importId)
 {
     return(ImportRepository.LoadImportHeadersByImportId(importId));
 }
Beispiel #29
0
 public RootsMagicImportService(IDbConnection dbData, IDbConnection dbImport, ILogger logger)
 {
     RootsMagic       = new RootsMagicRepository(dbData);
     ImportRepository = new ImportRepository(dbImport);
     Logger           = logger;
 }
Beispiel #30
0
        public ImportResult ProcessImport(FileStream dataStream, ImportParametersViewModel parameters, string userId)
        {
            var user = UserService.GetUserById(userId);

            if (user == null)
            {
                throw new Exception("Не вдалось завантажити дані користувача.");
            }

            SetImportStrategy(parameters.ImportMethod);

            var parsedImport  = ImportStrategy.ImportData(dataStream, parameters);
            var currentImport = ImportRepository.SaveImport(new UserImport
            {
                User         = user,
                FileName     = new FileInfo(dataStream.Name).Name,
                RecordsCount = parsedImport.Data.Count + parsedImport.ErrorsCount,
                ErrorsCount  = parsedImport.ErrorsCount,
                ImportDate   = DateTime.Now
            });

            ImportRepository.SaveImportParameters(ParseImportParameters(currentImport, parameters.Parameters));

            ImportRepository.SaveImportHeaders(parameters.HeaderParameters.Select(hp => new ImportHeader
            {
                Import        = currentImport,
                HeaderName    = hp.HeaderName,
                DataType      = ImportRepository.LoadDataTypeById((int)hp.DataType),
                PriorityLevel = ImportRepository.LoadPriorityLevelByPriority((int)hp.PriorityLevel)
            }).ToList());

            var importHeaders = ImportRepository.LoadImportHeadersByImportId(currentImport.Id);
            var importData    = new List <ImportData>();

            foreach (var dataRow in parsedImport.Data)
            {
                var rowCells = new List <ImportData>();
                foreach (var header in importHeaders)
                {
                    if (dataRow.ContainsKey(header.HeaderName))
                    {
                        rowCells.Add(new ImportData
                        {
                            Header    = header,
                            RowNumber = parsedImport.Data.IndexOf(dataRow) + 1,
                            Value     = dataRow[header.HeaderName]
                        });
                    }
                }
                importData.AddRange(rowCells);
            }

            ImportRepository.SaveImportData(importData);

            return(new ImportResult
            {
                Result = OperationResult.Success,
                ErrorFilePath = parsedImport.ErrorFilePath,
                Message = $"Опрацьовано записів: {currentImport.RecordsCount}. З них не розпізнано: {parsedImport.ErrorsCount}"
            });
        }
        public ImportViewModel GetImportViewModel(string path)
        {
            var repo = new ImportRepository(path);

            var vm = new ImportViewModel {
                Headers  = repo.Headers,
                Products = repo.Products.ToList(),
            };

            vm.RowDetails = GetRowDetails(vm.Headers, vm.Products);
            var list = new List <MappingOption> {
                new MappingOption {
                    Id = 1, Name = "Feature"
                },
                new MappingOption {
                    Id = 2, Name = "Identifers"
                },
                new MappingOption {
                    Id = 3, Name = "Specification"
                },
                new MappingOption {
                    Id = 4, Name = "Class"
                },
                new MappingOption {
                    Id = 5, Name = "Price"
                },
                new MappingOption {
                    Id = 6, Name = "Color"
                },
                new MappingOption {
                    Id = 7, Name = "Marketing Detail"
                },
                new MappingOption {
                    Id = 8, Name = "Activity"
                },
                new MappingOption {
                    Id = 9, Name = "Designation"
                },
                new MappingOption {
                    Id = 10, Name = "Model"
                },
                new MappingOption {
                    Id = 11, Name = "Sub Model"
                },
                new MappingOption {
                    Id = 12, Name = "Make"
                },
                new MappingOption {
                    Id = 13, Name = "Condition"
                },
                new MappingOption {
                    Id = 14, Name = "Quantity"
                },
                new MappingOption {
                    Id = 15, Name = "Media"
                },
                new MappingOption {
                    Id = 16, Name = "Status"
                }
            };

            vm.MappingOptions = list.OrderBy(l => l.Name).ToList();
            using (var ctx = new PrototypeContext()) {
                var mRepo = new ProximityMappingRepository(ctx);
                vm.Industries     = mRepo.GetIndustries();
                vm.ReferenceCodes = mRepo.GetReferenceCodes();
            }
            vm.SelectedIndustry = 2;

            vm.ActivityTypes = vm.ReferenceCodes.Where(rc => rc.Name == "Activity" &&
                                                       rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.ClassTypes = vm.ReferenceCodes.Where(rc => rc.Name == "Class" &&
                                                    rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.ColorTypes = vm.ReferenceCodes.Where(rc => rc.Name == "Color" &&
                                                    rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.Designations = vm.ReferenceCodes.Where(rc => rc.Name == "Designation" &&
                                                      rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.PriceTypes = vm.ReferenceCodes.Where(rc => rc.Name == "Price" &&
                                                    rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.SpecificationTypes = vm.ReferenceCodes.Where(rc => rc.Name == "Specification" &&
                                                            rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.StatusTypes = vm.ReferenceCodes.Where(rc => rc.Name == "Status" &&
                                                     rc.IndustryId == vm.SelectedIndustry).ToList();
            vm.UnitTypes = vm.ReferenceCodes.Where(rc => rc.Name == "UnitType" &&
                                                   rc.IndustryId == vm.SelectedIndustry).ToList();

            return(vm);
        }