Exemplo n.º 1
1
        public FineUploaderResult AccountsImport(FineUpload upload)
        {
            try
            {
                List<Account> list;

                using (var csv = new CsvReader(new StreamReader(upload.InputStream)))
                {
                    csv.Configuration.ClassMapping<AccountMap, Account>();
                    list = csv.GetRecords<Account>().ToList();
                }

                //save to \\userdata01\Localuser\Users\HTMLEngager
                var folder = ConfigurationManager.AppSettings["WebDriver/AccountImport/Folder"];
                var fileName = string.Format("{0}\\{1:yyyyMMddHHmmssfff}.csv", folder, DateTime.UtcNow);
                using (var csv = new CsvWriter(new StreamWriter(fileName)))
                {
                    csv.Configuration.ClassMapping<AccountMap, Account>();
                    csv.WriteRecords(list);
                }

                //call mark sporc and wait for results
                var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WebDriverEngager"].ConnectionString);
               
                var p = new DynamicParameters();
                p.Add("@SourceFilename", fileName);
                p.Add("@Updated", dbType: DbType.Int32, direction: ParameterDirection.Output);
                p.Add("@Inserted", dbType: DbType.Int32, direction: ParameterDirection.Output);
                conn.Open();
                conn.Execute("HTMLEngagerUpsert", p, commandType: CommandType.StoredProcedure);
                conn.Close();

                //delete file after import
                System.IO.File.Delete(fileName);

                return new FineUploaderResult(true, new
                                                    {
                                                        accountCount = list.Count(),
                                                        insertCount = p.Get<int>("@Inserted"),
                                                        updateCount = p.Get<int>("@Updated")
                                                    });
            }
            catch (Exception ex)
            {
                return new FineUploaderResult(false, error: ex.Message);
            }
        }
Exemplo n.º 2
0
            public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
            {
                var request = controllerContext.RequestContext.HttpContext.Request;
                var formUpload = request.Files.Count > 0;

                // find filename
                var xFileName = request.Headers["X-File-Name"];
                var qqFile = request["qqfile"];
                var formFilename = formUpload ? request.Files[0].FileName : null;

                var upload = new FineUpload
                {
                    Filename = xFileName ?? qqFile ?? formFilename,
                    InputStream = formUpload ? request.Files[0].InputStream : request.InputStream
                };

                return upload;
            }