public ActionResult Create(TopicViewModel topicViewModel) { if (ModelState.IsValid) { Topic topic = new Topic { Code = topicViewModel.Topic.Code, Naam = topicViewModel.Topic.Naam, Inhoud = topicViewModel.Topic.Inhoud, Leerdoel = topicViewModel.Topic.Leerdoel, Werkvorm = db.Werkvormen.Find(topicViewModel.Topic.Werkvorm.Id), Niveau = db.Niveaus.Find(topicViewModel.Topic.Niveau.Id), Duur = db.Tijdsduren.Find(topicViewModel.Topic.Duur.Id) }; topic.Benodigdheden = UpdateList(topicViewModel.BenodigdheidIds, topic.Benodigdheden); topic.Certificeringen = UpdateList(topicViewModel.CertificeringenIds, topic.Certificeringen); topic.Voorkennis = UpdateList(topicViewModel.VoorkennisIds, topic.Voorkennis); topic.PercipioLinks = UpdateList(topicViewModel.PercipioLinkIds, topic.PercipioLinks); db.Topics.Add(topic); db.SaveChanges(); return RedirectToAction("Index"); } FillTopicViewModelLists(topicViewModel); return View(topicViewModel); }
public ActionResult Create(CurriculumTemplateViewModel curriculumTemplateViewModel) { if (ModelState.IsValid) { CurriculumTemplate curriculumTemplate = curriculumTemplateViewModel.CurriculumTemplate; foreach (int topicId in curriculumTemplateViewModel.TopicIds) { Topic topic = db.GetFromDatabase <Topic>(topicId); curriculumTemplate.Topics.Add(topic); } db.CurriculumTemplates.Add(curriculumTemplate); db.SaveChanges(); // COMMENT: This code can probably be removed /* * if (curriculumViewModel.StudentId != 0) * { * return RedirectToAction("Details", "Student", new { id = curriculumViewModel.StudentId }); * } */ return(RedirectToAction("Index")); } curriculumTemplateViewModel.AlleTopics = db.Topics.Where(t => !t.IsDeleted).ToList(); curriculumTemplateViewModel.AlleTopics = db.Topics.ToList(); return(View(curriculumTemplateViewModel)); }
public ActionResult Create([Bind(Include = "Certificering,Naam")] Certificering certificering) { if (ModelState.IsValid) { db.Certificeringen.Add(certificering); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(certificering)); }
public ActionResult Create([Bind(Include = "Id,Naam")] Tag tag) { if (ModelState.IsValid) { db.Tags.Add(tag); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tag)); }
public ActionResult Create([Bind(Include = "Id,Voornaam,Achternaam,AanmeldDatum")] Student student) { if (ModelState.IsValid) { db.Studenten.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "Id,Eenheid")] Tijdsduur tijdsduur) { if (ModelState.IsValid) { db.Tijdsduren.Add(tijdsduur); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tijdsduur)); }
public ActionResult Create([Bind(Include = "Id,Naam")] Werkvorm werkvorm) { if (ModelState.IsValid) { db.Werkvormen.Add(werkvorm); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(werkvorm)); }
public ActionResult Create([Bind(Include = "Id,Naam")] Benodigdheid benodigdheid) { if (ModelState.IsValid) { db.Benodigdheden.Add(benodigdheid); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(benodigdheid)); }
public ActionResult Create([Bind(Include = "Id,Naam")] Niveau niveau) { if (ModelState.IsValid) { db.Niveaus.Add(niveau); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(niveau)); }
public ActionResult Create([Bind(Include = "Id,Link")] PercipioLink percipioLink) { if (ModelState.IsValid) { db.PercipioLinks.Add(percipioLink); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(percipioLink)); }
public ActionResult Create([Bind(Include = "StudentId,CurriculumTemplateId")] CurriculumViewModel curriculumViewModel) { if (ModelState.IsValid) { Student student = db.GetFromDatabase <Student>(curriculumViewModel.StudentId); var curriculumTemplate = db.GetFromDatabase <CurriculumTemplate>(curriculumViewModel.CurriculumTemplateId); var topics = curriculumTemplate.Topics; Curriculum curriculum = new Curriculum(); curriculum.Naam = curriculumTemplate.Naam; foreach (var topic in topics) { //var topic1 = db.GetFromDatabase<Topic>(topic.Id); CurriculumTopic t = new CurriculumTopic { TopicId = topic.Id, Topic = topic, Curriculum = curriculum, CurriculumId = curriculum.Id }; curriculum.Topics.Add(t); } curriculum.Student = student; student.Curricula.Add(curriculum); db.Curricula.Add(curriculum); db.Entry(student).State = EntityState.Modified; db.SaveChanges(); //// COMMENT: This code can probably be removed //if (curriculumViewModel.StudentId != 0) // return RedirectToAction("Details", "Student", new { id = curriculumViewModel.StudentId }); return(RedirectToAction("Details", "Student", new { id = curriculumViewModel.StudentId })); } return(View()); //curriculumTemplateViewModel.AlleTopics = db.Topics.Where(t => !t.IsDeleted).ToList(); //curriculumTemplateViewModel.AlleTopics = db.Topics.ToList(); //return View(curriculumTemplateViewModel); }
private static bool MakeNiveau(string item, SVSContext db) { bool success = false; if (db.Niveaus.Find(item) == null) { try { db.Niveaus.Add(new Niveau { Naam = item }); db.SaveChanges(); success = true; } catch { } } return(success); }
private static bool MakeWerkvorm(string item, SVSContext db) { bool success = false; if (db.Werkvormen.Find(item) == null) { try { db.Werkvormen.Add(new Werkvorm { Naam = item }); db.SaveChanges(); success = true; } catch { } } return(success); }
private static bool MakeDuur(string item, SVSContext db) { bool success = false; if (db.Tijdsduren.Find(item) == null) { try { db.Tijdsduren.Add(new Tijdsduur { Eenheid = item }); db.SaveChanges(); success = true; } catch { } } return(success); }
private static bool MakeCert(string item, SVSContext db) { bool success = false; if (db.Certificeringen.Find(item) == null) { try { db.Certificeringen.Add(new Certificering { Naam = item }); db.SaveChanges(); success = true; } catch { } } return(success); }
/// <summary> /// Reads and parses data from a $-separated file and writes the parsed Topics into the database /// </summary> /// <param name="db">The database context to write the TopicModels to</param> /// <param name="filePath">The path to the $-separated file</param> public void GetTopicSheetData(string filePath) { //string pathToSheetOne = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + @"\Data\InfraWorkshopsSheet1.csv"; //Console.WriteLine(pathToSheetOne); StreamReader SheetOneReader = new StreamReader(filePath); string unsplitTopicEntry; //Makes a list of headers var Headers = SheetOneReader.ReadLine().Split('$').ToList(); for (int i = 0; i < Headers.Count; i++) { Headers[i] = Headers[i].Trim(' ', '*', '"', '-', '•'); } //Reads lines until the splitline list has as many items as there are headers while ((unsplitTopicEntry = SheetOneReader.ReadLine() + LF) != LF.ToString()) { var splitLine = unsplitTopicEntry.Split('$').ToList(); for (int i = 0; i < splitLine.Count; i++) { splitLine[i] = splitLine[i].Trim(' ', '*', '"', '-', '•'); } //If the splitline doesn't contain enough items, keep reading lines while (splitLine.Count < Headers.Count()) { //Add the Linefeed character to the entries to preserve newlines in the data var moreLine = SheetOneReader.ReadLine() + LF; var moreSplits = moreLine.Split('$').ToList(); for (int i = 0; i < moreSplits.Count; i++) { moreSplits[i] = moreSplits[i].Trim(' ', '*', '"', '-', '•'); } //Join the last and first entry, cut off first entry splitLine[splitLine.Count - 1] = splitLine[splitLine.Count - 1] + moreSplits[0]; moreSplits.Remove(moreSplits[0]); //and add the newline to the current line foreach (var item in moreSplits) { var titem = item.Trim(' ', '*', '"', '-', '•'); splitLine.Add(titem); } } //Make a new topicmodel to add to the database with the data from the splitline Topic topicModel = new Topic(); int counter = 0; foreach (var splitTopicEntry in splitLine) { string type = Headers[counter].Trim(' ', '*', '"', '-', '•'); counter++; if (splitTopicEntry != string.Empty && splitTopicEntry != LF.ToString()) { switch (type) { case "#": //The Id will be generated by the database break; case "Code": topicModel.Code = splitTopicEntry; break; case "Niveau": topicModel.Niveau = FindNiveau(splitTopicEntry); break; case "Topic": topicModel.Naam = splitTopicEntry; break; case "Duur": topicModel.Duur = FindDuration(splitTopicEntry); break; case "Werkvorm(en)": topicModel.Werkvorm = FindWerkvorm(splitTopicEntry); break; case "Leerdoel(en)": topicModel.Leerdoel = splitTopicEntry; break; case "Certificering": topicModel.Certificeringen = FindCerts(splitTopicEntry); break; case "Benodigde voorkennis": topicModel.Voorkennis = FindVoorkennis(splitTopicEntry); break; case "Inhoud": topicModel.Inhoud = splitTopicEntry; break; case "Benodigdheden": topicModel.Benodigdheden = FindBenodigdheden(splitTopicEntry); break; case "Percipio links": topicModel.PercipioLinks = FindLinks(splitTopicEntry); break; case "Tags 1": topicModel.Tags.Add(FindTag(splitTopicEntry)); break; case "Tags 2": topicModel.Tags.Add(FindTag(splitTopicEntry)); break; case "Tags 3": topicModel.Tags.Add(FindTag(splitTopicEntry)); break; default: break; } } } db.Topics.Add(topicModel); db.SaveChanges(); } }