public ActionResult Create(student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    employee employee = db.employees.SingleOrDefault(emp => emp.employeeid == student.studentid);
                    if (employee != null)
                    {
                        ModelState.AddModelError("studentid", "Student ID is already in ues.");
                    }
                    else
                    {
                        db.students.AddObject(student);
                        db.SaveChanges();
                        return RedirectToAction("Index");
                    }
                }

                ViewBag.campus = new SelectList(db.campus, "cname", "cname", student.campus);
                ViewBag.programcode = new SelectList(db.programs, "programcode", "programname", student.programcode);
                return View(student);
            }
            catch (Exception)
            {
                return RedirectToAction("Create", "Student");
            }
        }
        //
        // GET: /Student/Create
        /// <summary>
        /// Grabs required data data to populate the ViewBag
        /// </summary>
        /// <returns></returns>
        public ActionResult Create()
        {
            ViewBag.campus = new SelectList(db.campus, "cname", "cname");
            ViewBag.programcode = new SelectList(db.programs, "programcode", "programname");

            //var program = db.programs;
            //List<String> collection = new List<String>();
            //foreach (program pcode in program)
            //{
            //    collection.Add(pcode.programcode.ToString().Trim() + " - " + pcode.programname.ToString().Trim());
            //}
            //ViewBag.programcode = new SelectList(collection);
            student student = new student() { enrolled = true, fulltimestatus = true };
            return View(student);
        }
 public ActionResult Edit(student student)
 {
     if (ModelState.IsValid)
     {
         db.students.Attach(student);
         db.ObjectStateManager.ChangeObjectState(student, EntityState.Modified);
         db.SaveChanges();
         return RedirectToAction("Details/" + student.studentid);
     }
     ViewBag.campus = new SelectList(db.campus, "cname", "cname", student.campus);
     ViewBag.programcode = new SelectList(db.programs, "programcode", "programname", student.programcode);
     return View(student);
 }
Пример #4
0
        private void Fixupstudent(student previousValue)
        {
            if (IsDeserializing)
            {
                return;
            }

            if (previousValue != null && previousValue.issues.Contains(this))
            {
                previousValue.issues.Remove(this);
            }

            if (student != null)
            {
                if (!student.issues.Contains(this))
                {
                    student.issues.Add(this);
                }

                studentid = student.studentid;
            }
            if (ChangeTracker.ChangeTrackingEnabled)
            {
                if (ChangeTracker.OriginalValues.ContainsKey("student")
                    && (ChangeTracker.OriginalValues["student"] == student))
                {
                    ChangeTracker.OriginalValues.Remove("student");
                }
                else
                {
                    ChangeTracker.RecordOriginalValue("student", previousValue);
                }
                if (student != null && !student.ChangeTracker.ChangeTrackingEnabled)
                {
                    student.StartTracking();
                }
            }
        }