Пример #1
0
        public ActionResult Delete(TeacherModel model)
        {
            CourseContext ctx = new CourseContext();
              ctx.Teachers.Remove(ctx.Teachers.FirstOrDefault(c => c.ID == model.ID));

              return View();
        }
Пример #2
0
        public ActionResult Add(TeacherModel model)
        {
            var memberMapper = new MemberMapper();
              memberMapper.CreateMap<TeacherModel, Teacher>(source =>
            new Teacher()
            {
              Phone = source.SchoolPhone,
              IDNumber = source.Identifier,
              RoomNumber = source.RoomNr
            });

              CourseContext ctx = new CourseContext();
              ctx.Teachers.Add(memberMapper.Map<Teacher>(model));
              ctx.SaveChanges();

              return RedirectToAction("Index");
        }
Пример #3
0
        public ActionResult Update(TeacherModel model)
        {
            CourseContext ctx = new CourseContext();
              var teacher = ctx.Teachers.FirstOrDefault(c => c.ID == model.ID);

              teacher.FirstName = model.FirstName;
              teacher.LastName = model.LastName;
              teacher.Email = model.Email;
              teacher.RoomNumber = model.RoomNr;
              teacher.Phone = model.SchoolPhone;

              ctx.SaveChanges();

              return RedirectToAction("Index");
        }