Exemplo n.º 1
0
        public IActionResult CreateClass(NewClassViewModel newClass)
        {
            UpdateControllerProperties("CreateClass");

            var newClassName = newClass.NewClassName;

            newClass.NewClass.ClassName = newClassName;

            var startDate = DateTime.Now;

            newClass.NewClass.StartDate = startDate;

            ClassRepository.CreateNewClass(newClass.NewClass);
            int newClassId = ClassRepository.GetClassId(newClass.NewClass);



            foreach (var mentor in newClass.Mentors)
            {
                if (mentor.IsAssigned.Equals(true))
                {
                    int mentorId = ClassRepository.GetMentorId(mentor.UserId);
                    ClassRepository.AssignMentorsToClass(mentorId, newClassId, startDate);
                }
            }

            return(RedirectToAction("Classes"));
        }
Exemplo n.º 2
0
        public IActionResult CreateClass()
        {
            UpdateControllerProperties("CreateClass");

            var mentors   = UserDAO.ReadAllMentors();
            var viewModel = new NewClassViewModel {
                Mentors = mentors
            };

            return(View(viewModel));
        }
        public ActionResult New(Class Class = null)
        {
            NewClassViewModel model = new NewClassViewModel()
            {
                Class   = Class,
                Courses = _context.Courses.ToList(),
                Staff   = _context.Staff.ToList()
            };

            if (Class == null)
            {
                model.Class = new Class();
            }

            return(View("ClassForm", model));
        }
        public ActionResult Save(Class Class)
        {
            Class.Instructor = _context.Staff.SingleOrDefault(s => s.Id == Class.InstructorId);
            Class.course     = _context.Courses.SingleOrDefault(c => c.Id == Class.CourseId);
            Class classInDb = _context.Classes.SingleOrDefault(c => c.Id == Class.Id);

            if (!ModelState.IsValid)
            {
                NewClassViewModel model = new NewClassViewModel()
                {
                    Class   = Class,
                    Courses = _context.Courses.ToList(),
                    Staff   = _context.Staff.ToList()
                };

                return(View("ClassForm", model));
            }

            if (classInDb == null)
            {
                _context.Classes.Add(Class);
            }
            else
            {
                foreach (PropertyInfo property in typeof(Class).GetProperties())
                {
                    if (property.CanWrite)
                    {
                        property.SetValue(classInDb, property.GetValue(Class, null), null);
                    }
                }
            }

            _context.SaveChanges();

            ClassesViewModel classesViewModel = new ClassesViewModel()
            {
                Classes = _context.Classes.Include("Course").ToList(),
                Staff   = _context.Staff.Where(s => _context.Classes.Select(c => c.Instructor.Id).Contains(s.Id)).ToList()
            };



            return(View("Index", classesViewModel));
        }