public static void DeleteSpeaker(int id)
 {
     using (var ctx = new ConferenceContext())
     {
         var speaker = ctx.Speakers.Find(id);
         ctx.Speakers.Remove(speaker);
         ctx.SaveChanges();
     }
 }
 public static bool Edit(Speaker speaker, ModelStateDictionary msd)
 {
     if (msd.IsValid)
     {
         using (var ctx = new ConferenceContext())
         {
             ctx.Entry(speaker).State = System.Data.Entity.EntityState.Modified;
             ctx.SaveChanges();
             return true;
         }
     }
     return false;
 }
 public static bool Create(Speaker speaker, ModelStateDictionary msd)
 {
     if (msd.IsValid)
     {
         using (var ctx = new ConferenceContext())
         {
             ctx.Speakers.Add(speaker);
             ctx.SaveChanges();
             return true;
         }
     }
     return false;
 }
Beispiel #4
0
        public ActionResult Create(Session session)
        {
            if(!ModelState.IsValid){
                return View(session);
            }

            try
            {
                ConferenceContext context = new ConferenceContext();
                context.Sessions.Add(session);
                context.SaveChanges();
            }
            catch (Exception ex)
            {

                ModelState.AddModelError("Error", ex.Message);
                return View(session);
            }

            TempData["Created"] = "Created" + session.Title;
            return RedirectToAction("Index");
        }