Example #1
0
        public ActionResult Update(StudentFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Departments = _unitOfWork.Departments.GetDepartments();
                return(View("StudentForm", viewModel));
            }


            var studentInDb = _unitOfWork.Students.GetStudent(viewModel.Id);

            studentInDb.Id   = viewModel.Id;
            studentInDb.Name = viewModel.Name;


            studentInDb.SemesterDate = viewModel.GetBirthDate();


            studentInDb.DivisionD    = viewModel.DivisionD;
            studentInDb.DepartmentId = viewModel.Department;

            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Students")
                   );
        }
Example #2
0
        public ActionResult Create(StudentFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Departments = _unitOfWork.Departments.GetDepartments();
                return(View("StudentForm", viewModel));
            }

            var student = new Student
            {
                Name         = viewModel.Name,
                LevelG       = viewModel.LevelG,
                DateTime     = DateTime.Now,
                SemesterDate = viewModel.GetBirthDate(),

                DepartmentId = viewModel.Department,
                DivisionD    = viewModel.DivisionD,
                Token        = (2018 + _unitOfWork.Students.GetStudents().Count()).ToString().PadLeft(7, '0')
            };

            _unitOfWork.Students.Add(student);
            _unitOfWork.Complete();
            return(RedirectToAction("Index", "Students"));
        }