public ActionResult Add(PublicationViewModel viewModel) { // Research field if (!ResearchFields.Contains(viewModel.ResearchField)) { ModelState.AddModelError("ResearchField", "The research field you chosen doesn't exist."); } // Research year if (!ResearchYears.Contains(viewModel.ResearchYear)) { ModelState.AddModelError("ResearchYear", "The year you chosen were incorrect."); } // Fill our database model data. Publication pub = new Publication(); pub.Abstract = viewModel.Abstract; pub.Authors = viewModel.Authors; pub.National = viewModel.National == "National"; pub.ResearchField = viewModel.ResearchField; pub.ResearchYear = viewModel.ResearchYear; pub.Title = viewModel.Title; if (Request.Form["published_in"] == "journal") { pub.Details = viewModel.JournalName; pub.Identifier = viewModel.JournalDOI; pub.PubType = Publication.PublicationType.Journal; } else if (Request.Form["published_in"] == "confrance") { pub.Details = viewModel.ConfranceDetails; pub.PubType = Publication.PublicationType.Confrance; } else { pub.Details = viewModel.BookName; pub.Identifier = viewModel.BookISSN; pub.PubType = Publication.PublicationType.Book; } if (ModelState.IsValid) { db.Publications.Add(pub); db.SaveChanges(); return(RedirectToAction("Index")); } viewModel.ResearchFieldsList = new SelectList(ResearchFields, pub.ResearchField); viewModel.ResearchYearsList = new SelectList(ResearchYears, pub.ResearchYear); viewModel.NationalityList = new SelectList(new string[] { "National", "International" }, viewModel.National); return(View(viewModel)); }
public int Complete() { return(_context.SaveChanges()); }