Пример #1
0
        public ActionResult Edit([Bind(Include = "Id,LastName,FirstName,School,WorkPhone,CellPhone,Email")]
                                 AddEditTeacherViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var teacher = _db.Teachers.Find(viewModel.Id);
                if (teacher != null)
                {
                    teacher.LastName  = viewModel.LastName;
                    teacher.FirstName = viewModel.FirstName;
                    teacher.WorkPhone = viewModel.WorkPhone;
                    if (viewModel.School != null)
                    {
                        teacher.School = (from s in _db.Schools where s.Id == viewModel.School.Id select s).Single();
                    }

                    teacher.CellPhone = viewModel.CellPhone;
                    teacher.Email     = viewModel.Email;
                }

                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(viewModel));
        }
Пример #2
0
        // GET: Teachers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Teacher teacher = _db.Teachers.Find(id);

            if (teacher == null)
            {
                return(HttpNotFound());
            }

            AddEditTeacherViewModel viewModel = new AddEditTeacherViewModel
            {
                Id        = teacher.Id,
                LastName  = teacher.LastName,
                FirstName = teacher.FirstName,
                //viewModel.School = teacher.School;
                WorkPhone = teacher.WorkPhone,
                CellPhone = teacher.CellPhone,
                Email     = teacher.Email
            };

            return(View(viewModel));
        }
        public IActionResult Add()
        {
            var teachers = _dbContext.Teachers;

            AddEditTeacherViewModel model = new AddEditTeacherViewModel();

            return(View(model));
        }
 public IActionResult Add(AddEditTeacherViewModel model)
 {
     if (ModelState.IsValid)
     {
         Teacher teacher = new Teacher()
         {
             FirstName = model.FirstName,
             LastName  = model.LastName,
             Phone     = model.Phone1,
             Email     = model.Email
         };
         _dbContext.Teachers.Add(teacher);
         _dbContext.SaveChanges();
         return(RedirectToAction(nameof(AllTeachers)));
     }
     return(View());
 }
Пример #5
0
        public ActionResult Create([Bind(Include = "Id,LastName,School,FirstName,WorkPhone,CellPhone,Email")] AddEditTeacherViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Teacher teacher = new Teacher
                {
                    FirstName = viewModel.FirstName,
                    LastName  = viewModel.LastName,
                    CellPhone = viewModel.CellPhone,
                    WorkPhone = viewModel.WorkPhone,
                    Email     = viewModel.Email
                };
                _db.Teachers.Add(teacher);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(viewModel));
        }
Пример #6
0
        // GET: Teachers/Create
        public ActionResult Create()
        {
            AddEditTeacherViewModel viewModel = new AddEditTeacherViewModel();

            return(View(viewModel));
        }