public ActionResult Create(WettenVM wettenVM)
        {
            string title = "Nieuw";

            if (ModelState.IsValid)
            {
                Wetten wetten = new Wetten();
                wetten.Fill(wettenVM);
                try
                {
                    db.Wetten.Add(wetten);

                    foreach (Onderwerp o in wettenVM.OnderwerpenLijst)
                    {
                        if (o.Geselecteerd)
                        {
                            WetScope wetscope = new WetScope();
                            wetscope.Fill(wettenVM.wet.WetID, o);
                            db.WetScope.Add(wetscope);
                        }
                    }
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    string exnum = ex.Message;

                    string emsg   = "Wet '" + wettenVM.wet.WetID.Trim() + "' bestaat al";
                    string elevel = wettenVM.MessageSection.Error;
                    wettenVM.MessageSection.SetMessage(title, elevel, emsg);
                    return(View(wettenVM));
                }
                TempData["BCmessage"]    = "Wet " + wettenVM.wet.WetNaam.Trim() + " is nu aangemaakt";
                TempData["BCerrorlevel"] = wettenVM.MessageSection.Info;

                return(RedirectToAction("Index"));
            }

            string level = wettenVM.MessageSection.Error;
            string msg   = "ERROR - Wet " + wettenVM.wet.WetNaam.Trim() + " is NIET aangemaakt";

            wettenVM.MessageSection.SetMessage(title, level, msg);
            return(View(wettenVM));
        }
        public ActionResult Edit(WettenVM wettenVM)
        {
            string title = "Bewerken";

            if (ModelState.IsValid)
            {
                Wetten wetten = new Wetten();
                wetten.Fill(wettenVM);
                try
                {
                    db.Entry(wetten).State = EntityState.Modified;
                    db.SaveChanges();

                    foreach (Onderwerp o in wettenVM.OnderwerpenLijst)
                    {
                        WetScope searchdb = db.WetScope.Find(wettenVM.wet.WetID, o.OnderwerpID);
                        if (o.Geselecteerd)
                        {
                            if (searchdb == null)
                            {
                                WetScope ws = new WetScope();
                                ws.Fill(wettenVM.wet.WetID, o);
                                db.WetScope.Add(ws);
                            }
                            else
                            {
                                WetScope ws1 = new WetScope();
                                ws1.Fill(wettenVM.wet.WetID, o);
                                db.WetScope.Attach(ws1);
                                db.Entry(ws1).State = EntityState.Modified;
                            }
                            db.SaveChanges();
                        }
                        else
                        {
                            if (searchdb != null)
                            {
                                db.WetScope.Remove(searchdb);
                                db.SaveChanges();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string exnum = ex.Message;

                    string emsg   = "Wet '" + wettenVM.wet.WetID.Trim() + "' bestaat al? (" + exnum + ")";
                    string elevel = wettenVM.MessageSection.Error;
                    wettenVM.MessageSection.SetMessage(title, elevel, emsg);
                    return(View(wettenVM));
                }
                TempData["BCmessage"]    = "Wet '" + wettenVM.wet.WetNaam.Trim() + "' is gewijzigd";
                TempData["BCerrorlevel"] = wettenVM.MessageSection.Info;

                return(RedirectToAction("Details", new { WetID = wettenVM.wet.WetID }));
            }

            string level = wettenVM.MessageSection.Error;
            string msg   = "ERROR - Wet '" + wettenVM.wet.WetNaam.Trim() + "' is NIET gewijzigd";

            wettenVM.MessageSection.SetMessage(title, level, msg);
            return(View(wettenVM));
        }