// GET: Events/Create/5 public ActionResult Create(int?id) { AgendaItemCreate item = new AgendaItemCreate(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } item.MeetingID = (int)id; return(View(item)); }
public ActionResult Create([Bind(Include = "ID,Title,Description,MeetingID,Order")] Event @event, AgendaItemCreate item) { if (db.Meetings.Find(item.MeetingID) == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ModelState.IsValid) { var orderCount = db.Events.Include(m => m.Meeting).ToList().Where(e => e.Meeting.ID == item.MeetingID).Count(); //@event.Meeting.ID = item.MeetingID; //This is bad why oh why would you do this? @event.Meeting = db.Meetings.Find(item.MeetingID); @event.Order = orderCount + 1; db.Events.Add(@event); db.SaveChanges(); return(RedirectToAction("EditAgenda", new { id = item.MeetingID })); } return(View(@event)); }