-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBulkUpload.cs
More file actions
47 lines (44 loc) · 1.47 KB
/
BulkUpload.cs
File metadata and controls
47 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace Net_Interview_Question_API
{
public class BulkUpload
{
public static void DeleteEverything()
{
using (var db = new DBModelContext())
{
db.DBModel.RemoveRange(db.DBModel);
db.SaveChanges();
}
}
public static void LoadFile()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string file = dir + @"\FILE\questionnaire.csv";
using (var db = new DBModelContext())
{
using (var reader = new StreamReader(file))
{
List<string> listA = new List<string>();
int headers = 1;
while (!reader.EndOfStream)
{
if (headers != 1)
{
var line = reader.ReadLine();
var values = line.Split(',');
var questionnaire = new DBModel { User = values[0], Question = values[1], Answer = values[2], QuestionTags = values[3], Votes = values[4] };
db.DBModel.Add(questionnaire);
db.SaveChanges();
}
headers = 0;
}
}
}
}
}
}