Example #1
0
        public ActionResult Create(EventCreateModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    using (var db = new MySelfieEntities())
                    {
                        Event theEvent;

                        if (model.EventId == 0)
                        {
                            theEvent = new Event();

                            theEvent.MergeWithOtherType(model);

                            db.Events.Add(theEvent);
                        }
                        else
                        {
                            theEvent = db.Events.Where(x => x.EventId == model.EventId).FirstOrDefault();

                            theEvent.MergeWithOtherType(model);

                        }

                        db.SaveChanges();
                    }

                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("ex", ex);

                    return View(model);
                }

                return RedirectToAction("Index", "Event");
            }

            return View(model);
        }
Example #2
0
        public ActionResult Create(int id = 0)
        {
            EventCreateModel model = new EventCreateModel();

            try
            {
                using (var db = new MySelfieEntities())
                {
                    Event theEvent;
                    theEvent = db.Events.Where(x => x.EventId == id).FirstOrDefault();
                    model.MergeWithOtherType(theEvent);
                    return View(model);
                }
            }
            catch (Exception)
            {

               // throw;
            }

            return View();
        }
Example #3
0
        public ActionResult Delete(int id)
        {
            EventCreateModel model = new EventCreateModel();

            try
            {
                using (var db = new MySelfieEntities())
                {
                    Event theEvent;
                    theEvent = db.Events.Where(x => x.EventId == id).FirstOrDefault();
                    db.Events.Remove(theEvent);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
            }
            catch (Exception)
            {

                // throw;
            }

            return RedirectToAction("Index");
        }