public ActionResult Create([Bind(Include = "ID,Name")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(person));
        }
示例#2
0
        public ActionResult Create([Bind(Include = "ID,Description,Observation,Date,SpentDrink,SpentFood")] Event @event)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(@event);
                db.SaveChanges();
                return(RedirectToAction("Details", "Events", new { id = @event.ID }));
            }

            return(View(@event));
        }
        public ActionResult Create([Bind(Include = "ID,EventID,PersonID,Paid,Drink,Amount,Observation")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                if (enrollment.Amount > 0 && !enrollment.Paid)
                {
                    enrollment.Paid = true;
                }

                db.Enrollments.Add(enrollment);
                db.SaveChanges();
                return(RedirectToAction("Details", "Events", new { id = enrollment.EventID }));
            }

            ViewBag.EventList  = new SelectList(db.Events, "ID", "Description", enrollment.EventID);
            ViewBag.PersonList = new SelectList(db.Persons, "ID", "Name", enrollment.PersonID);
            return(View(enrollment));
        }