Esempio n. 1
0
        public ActionResult Upload(HttpPostedFileBase file)
        {
            if (file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path     = AppDomain.CurrentDomain.BaseDirectory + "Upload\\" + fileName;
                file.SaveAs(path);

                var csv = new CsvReader(new StreamReader(path));
                csv.Configuration.RegisterClassMap <ImportMappers>();
                IEnumerable <ImportModel> eventList = csv.GetRecords <ImportModel>();

                EventRepo eventRepo = new EventRepo(new EventMapContext());
                foreach (ImportModel imported in eventList)
                {
                    Event convertEvents = ImportConverter.ConvertEvents(imported);
                    eventRepo.InsertEvent(convertEvents);
                }
                eventRepo.Save();
            }

            return(View());
        }