Beispiel #1
0
        public NewNotesPage(Term term, Course course)
        {
            InitializeComponent();

            BindingContext = viewModel = new NewCourseViewModel(term, course);
            Title          = $"Update {course.Title}'s Notes";
        }
Beispiel #2
0
        public ActionResult Register()
        {
            var model = new NewCourseViewModel();

            model.CourseType = FillCourseType();
            model.Active     = false;
            return(View(model));
        }
        public ActionResult Create()
        {
            var dp        = DB.Departments.ToList();
            var viewModel = new NewCourseViewModel
            {
                departments = dp
            };

            return(View(viewModel));
        }
Beispiel #4
0
        public IActionResult Add(NewCourseViewModel model)
        {
            var success = service.Add(
                Utility.GetUserContext().UserId,
                model.SubjectId,
                model.Title,
                model.Image,
                model.Content,
                model.Remarks,
                model.Objective);

            return(Ok(success));
        }
Beispiel #5
0
        public ActionResult New()
        {
            // Load the target groups
            //var targetGroups = _context.TargetGroups.ToList();

            var viewModel = new NewCourseViewModel();

            viewModel.Course = new Course();

            viewModel.TargetGroups = _context.TargetGroups.Select(t => new SelectListItem {
                Text = t.Name, Value = t.Id.ToString()
            })
                                     .ToList();

            return(View("CourseForm", viewModel));
        }
        public ActionResult CreateNewCourse(Course course)
        {
            var dps = DB.Departments.ToList();

            var viewModel = new NewCourseViewModel
            {
                departments = dps,
                Course      = course
            };

            return(View("Create", viewModel));

            DB.Courses.Add(course);
            DB.SaveChanges();

            return(RedirectToAction("Index", "Courses"));
        }
Beispiel #7
0
        public ValidationAppResult RegisterNewCourse(NewCourseViewModel newCourseViewModel)
        {
            var validationResult = new ValidationAppResult();

            BeginTransaction();

            var novoCurso = new Course(newCourseViewModel.Name, newCourseViewModel.Active, _courseTypeService.GetById(newCourseViewModel.CourseTypeId));

            validationResult = DomainToApplicationResult(_courseService.AddNewCourse(novoCurso));

            if (validationResult.IsValid)
            {
                Commit();
            }

            return(validationResult);
        }
Beispiel #8
0
        public ActionResult Save(Course course)
        {
            course.Category = _context.Categories.FirstOrDefault(c => c.Id == course.CategoryId);
            Course courseInDb = _context.Courses.SingleOrDefault(c => c.Id == course.Id);

            if (!ModelState.IsValid)
            {
                NewCourseViewModel viewModel = new NewCourseViewModel
                {
                    Course = new Course {
                        Name = "", GradeLevel = 0, Id = 0, CategoryId = 0, Category = new Category {
                            Id = 0, Name = ""
                        }
                    },
                    Catergories = _context.Categories.Include("Category").ToList()
                };

                return(View("CourseForm", viewModel));
            }
            if (courseInDb == null)
            {
                _context.Courses.Add(course);
            }
            else
            {
                foreach (PropertyInfo property in typeof(Course).GetProperties())
                {
                    if (property.CanWrite)
                    {
                        property.SetValue(courseInDb, property.GetValue(course, null), null);
                    }
                }
            }


            _context.SaveChanges();

            CoursesViewModel CoursesViewModel = new CoursesViewModel()
            {
                Courses = _context.Courses.Include("Category").OrderBy(c => c.GradeLevel).ToList(),
                Classes = _context.Classes.ToList()
            };

            return(View("Index", CoursesViewModel));
        }
Beispiel #9
0
        public ActionResult New(Course course = null)
        {
            if (course == null)
            {
                course = new Course {
                    Name = "", GradeLevel = 0, Id = 0, CategoryId = 0, Category = new Category {
                        Id = 0, Name = ""
                    }
                };
            }
            NewCourseViewModel viewModel = new NewCourseViewModel
            {
                Course      = course,
                Catergories = _context.Categories.ToList()
            };

            return(View("CourseForm", viewModel));
        }
Beispiel #10
0
        public ActionResult Edit(int id)
        {
            var course = _context.Courses.SingleOrDefault(c => c.Id == id);
            //if (course == null)


            var viewModel = new NewCourseViewModel();

            viewModel.Course       = course;
            viewModel.TargetGroups = _context.TargetGroups.Select(t => new SelectListItem {
                Text = t.Name, Value = t.Id.ToString()
            })
                                     .ToList();

            viewModel.CourseTargetGroups = _context.CourseTargetGroups.Where(c => c.CourseId == id).Select(c => c.TargetGroupId);


            return(View("CourseForm", viewModel));
        }
Beispiel #11
0
        public ActionResult Save(NewCourseViewModel viewModel)
        {
            var course = viewModel.Course;

            // if the course is zero add a new
            if (viewModel.Course.Id == 0)
            {
                course = _context.Courses.Add(viewModel.Course);
            }
            else
            {
                // map the Course object
                var tmpCourse = _context.Courses.Single(c => c.Id == course.Id);
                tmpCourse.Name                    = course.Name;
                tmpCourse.Description             = course.Description;
                tmpCourse.SupervisorTraining      = course.SupervisorTraining;
                tmpCourse.ValidNoOfDays           = tmpCourse.ValidNoOfDays;
                tmpCourse.WarnNoOfDayBeforeExpire = course.WarnNoOfDayBeforeExpire;

                // delete the course target groups
                _context.CourseTargetGroups.RemoveRange(_context.CourseTargetGroups.Where(c => c.CourseId == course.Id));
            }


            // add the new course target groups
            if (viewModel.CourseTargetGroups != null)
            {
                foreach (var id in viewModel.CourseTargetGroups)
                {
                    var courseTarget = new CourseTargetGroup
                    {
                        CourseId      = course.Id,
                        TargetGroupId = id
                    };

                    _context.CourseTargetGroups.Add(courseTarget);
                }
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Course"));
        }
Beispiel #12
0
        /// <summary>
        /// Adds the new course to the database with unique id created by the database
        /// </summary>
        /// <param name="newCourse"></param>
        /// <returns>the new course</returns>
        public CourseDTO CreateCourse(NewCourseViewModel newCourse)
        {
            try
            {
                var template = _db.CourseTemplates.SingleOrDefault(x => newCourse.TemplateID == x.TemplateID);
                if (template == null)
                {
                    throw new NoSchoolPreconditionFailedException();
                }

                Entities.Course course = new Entities.Course();
                course.TemplateID = template.TemplateID;
                course.Semester   = newCourse.Semester;
                course.StartDate  = newCourse.StartDate;
                course.EndDate    = newCourse.EndDate;
                course.MaxStudent = newCourse.MaxStudents;

                _db.Courses.Add(course);
                _db.SaveChanges();

                return(new CourseDTO
                {
                    ID = course.ID,
                    Template = template.TemplateID,
                    Name = template.Name,
                    StartDate = course.StartDate,
                    EndDate = course.EndDate,
                    Semester = course.Semester,
                    MaxStudent = course.MaxStudent,
                    StudentInCourse = 0
                });
            }
            catch (NoSchoolException)
            {
                throw;
            }
            catch
            {
                throw new NoSchoolInternalException();
            }
        }
Beispiel #13
0
        public ActionResult Register(NewCourseViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = _courseAppService.RegisterNewCourse(model);

                if (result.IsValid)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var item in result.Erros)
                    {
                        ModelState.AddModelError("", item.Message);
                    }
                }
            }
            model.CourseType = FillCourseType();
            return(View(model));
        }
Beispiel #14
0
        public IHttpActionResult CreateCourse(NewCourseViewModel newCourse)
        {
            if (!ModelState.IsValid)
            {
                return(StatusCode(HttpStatusCode.PreconditionFailed));
            }


            try
            {
                var createdCourse = _service.CreateCourse(newCourse);
                var location      = Url.Link("GetCourse", new { id = createdCourse.ID });
                return(Created(location, createdCourse));
            }
            catch (NoSchoolException nex)
            {
                if (nex is NoSchoolPreconditionFailedException)
                {
                    return(StatusCode(HttpStatusCode.PreconditionFailed));
                }

                return(StatusCode(HttpStatusCode.InternalServerError));
            }
        }
Beispiel #15
0
 public NewCoursePage(Term term, Course course = null)
 {
     InitializeComponent();
     BindingContext = viewModel = new NewCourseViewModel(term, course);
 }
Beispiel #16
0
 public ActionResult CreateCourse(NewCourseViewModel NewCourse)
 {
     return(null);
 }