Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,StartDate,EndDate")] Module @group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@group));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,UserName,Email,Address,phone")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Add(user);
                await db.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,ActivityType,Name,Description,StartTime,EndTime,Deadline")] Activities activities)
        {
            if (ModelState.IsValid)
            {
                _context.Add(activities);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(activities));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Name, Description, StartDate, EndDate, DocId, CourseId, ParentStartDate, ParentEndDate, CourseName")] ModuleAddViewModel @module)
        {
            if (ModelState.IsValid)
            {
                var model = _mapper.Map <Module>(@module);
                _context.Add(model);

                await _context.SaveChangesAsync();

                TempData["AlertMsg"] = "Module added";
                return(RedirectToAction(nameof(Details), new { id = model.Id }));
            }
            return(View(@module));
        }
Esempio n. 5
0
        public async Task <IActionResult> Create([Bind("Description, StartDate, EndDate, ModuleId, ModuleName, ActivityTypeId, ParentStartDate, ParentEndDate")] ActivityAddViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Activityy activity = _mapper.Map <Activityy>(viewModel);
                activity.ActivityType = await _context.ActivityType.FirstOrDefaultAsync(at => at.Id == viewModel.ActivityTypeId);

                activity.Module = await _context.Modules.FirstOrDefaultAsync(m => m.Id == viewModel.ModuleId);

                await _context.Activities.AddAsync(activity);

                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                TempData["AlertMsg"] = "Activity added";
                return(RedirectToAction("Details", "module", new { id = activity.Module.Id }));
            }


            var module = await _context.Modules.Include(m => m.Course).FirstOrDefaultAsync(m => m.Id == viewModel.ModuleId);

            if (module is null)
            {
                return(NotFound());
            }

            var course = await _context.Courses.FirstOrDefaultAsync(a => a.Id == module.CourseId);

            if (course == null)
            {
                return(NotFound());
            }

            viewModel.Course     = course;
            viewModel.Module     = module;
            viewModel.ModuleId   = module.Id;
            viewModel.ModuleName = module.Name;

            ViewData["ActivityTypeId"] = new SelectList(_context.Set <ActivityType>(), "Id", "Type");
            return(View(viewModel));
        }
Esempio n. 6
0
        public async Task <IActionResult> Delete(int id)
        {
            Course courseToDelete = await _context.Courses.Include(c => c.Users).FirstOrDefaultAsync(c => c.Id == id);

            if (courseToDelete is null)
            {
                return(NotFound());
            }

            var students = await _userManager.GetUsersInRoleAsync("Student");

            var studentsInCourse = students.Where(s => s.CourseId == courseToDelete.Id);

            _context.Remove(courseToDelete);
            _context.RemoveRange(studentsInCourse);

            await _context.SaveChangesAsync();

            TempData["AlertMsg"] = "Course deleted";
            return(RedirectToAction(nameof(Index)));
        }