Exemplo n.º 1
0
        private static async Task Import(
            SecretService secretService, string csvFile)
        {
            var csvImportService = new CsvImportService();
            var fi      = new FileInfo(csvFile);
            var secrets = csvImportService.Load(fi);
            var count   = 0;

            try
            {
                foreach (var secret in secrets)
                {
                    await secretService.StoreAsync(secret);

                    count++;
                    Console.WriteLine($"\tAdded {secret.Name}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(
                    $"Error after importing {count} records! {ex}");
                Console.ReadLine();
            }
            Console.WriteLine($"\tAdded {count} secrets");
        }
        public ActionResult Import(CsvFile file)
        {
            // ファイルチェック
            if (!ModelState.IsValid)
            {
                return(View());
            }

            // ファイル読み込み
            CsvImportService csvImportService = new CsvImportService(file.UploadFile.InputStream);

            // バリデーション
            if (!csvImportService.IsValid)
            {
                ViewBag.ErrorMessageList = csvImportService.ErrorMessageList;
                return(View());
            }

            // モデル取得
            List <Parent> parentList = csvImportService.ParentList;

            // DB 登録
            parentList.ForEach(p => db.Parents.Add(p));
            db.SaveChanges();

            ViewBag.SuccessMessage = "インポートに成功しました。";
            return(View());
        }
Exemplo n.º 3
0
        public virtual ActionResult ParseCsv(CsvImportViewModel model)
        {
            var parsedEmployees = CsvImportService.parseEmployees(model.CsvFile.InputStream);

            var employees = EmployeeRepository.ToList();

            foreach (var parsedEmployee in parsedEmployees)
            {
                try
                {
                    var employee = employees.Single(x => x.Name == parsedEmployee.Name);
                    employee.Birthdate        = parsedEmployee.Birthdate;
                    employee.ContractStart    = parsedEmployee.ContractStart;
                    employee.SocialSecurityID = parsedEmployee.SocialSecurityID;
                    employee.PhoneNumber      = parsedEmployee.PhoneNumber;
                    employee.Skype            = parsedEmployee.Skype;
                    employee.Email            = parsedEmployee.Email;
                    EmployeeRepository.SaveOrUpdate(employee);
                }
                catch (Exception)
                {
                    continue;
                }
            }
            EmployeeRepository.Commit();

            return(View(MVC.Admin.Views.EditEmployees, new WorkersViewModel()
            {
                Employees = EmployeeRepository.AsDto()
            }));
        }
Exemplo n.º 4
0
 public void ImportFromCsv(string filePath)
 {
     CsvImportService.Import(filePath);
 }
Exemplo n.º 5
0
 public CenterFacade()
 {
     CenterRepository = new CenterRepository();
     CsvImportService = new CsvImportService();
     CentersQuery     = new CentersQuery();
 }