Пример #1
0
        public ActionResult Create(ClassViewModel result)
        {
            if (ModelState.IsValid)
            {
                result.ClassModel.Education = db.Educations.ToList().Where(e => e.Id.Equals(result.Education)).SingleOrDefault();

                db.Classes.Add(result.ClassModel);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            IEnumerable<SelectListItem> items = from s in db.Educations.ToList()
                                                select new SelectListItem { Text = s.Name, Value = s.Id.ToString() };

            ViewBag.Educations = items;

            return View(result);
        }
Пример #2
0
        public ActionResult Edit(ClassViewModel result)
        {
            if (ModelState.IsValid)
            {
                var classModel = db.Classes.Find(result.ClassModel.Id);
                classModel.ClassName = result.ClassModel.ClassName;
                classModel.Education = db.Educations.ToList().Where(e => e.Id.Equals(result.Education)).SingleOrDefault();

                db.Entry(classModel).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            IEnumerable<SelectListItem> items = from s in db.Educations.ToList()
                                                select new SelectListItem { Text = s.Name, Value = s.Id.ToString() };

            ViewBag.Educations = items;

            return View(result);
        }
Пример #3
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            ClassModel classmodel = db.Classes.Find(id);
            if (classmodel == null)
            {
                return HttpNotFound();
            }

            IEnumerable<SelectListItem> items = from s in db.Educations.ToList()
                                                select new SelectListItem { Text = s.Name, Value = s.Id.ToString() };

            ViewBag.Educations = items;

            var model = new ClassViewModel();
            model.ClassModel = classmodel;
            model.SelectedEducation = classmodel.Education.Id;

            return View(model);
        }