// GET: StudentCourseAssociation/Edit/5
        public ActionResult Edit(int id)
        {
            StudentCourseAssociation          studentCourseAssociation          = studentCourseAssociationService.Get(id);
            StudentCourseAssociationViewModel studentCourseAssociationViewModel = new StudentCourseAssociationViewModel
            {
                StudentCourseAssociation = studentCourseAssociation,
                Students = studentService.GetAll(),
                Courses  = courseService.GetAll()
            };

            return(View(studentCourseAssociationViewModel));
        }
示例#2
0
        public async Task RemoveStudentFromCourse(StudentCourseAssociation association)
        {
            await using var connection =
                            new NpgsqlConnection(Environment.GetEnvironmentVariable("DATABASE"));

            await connection.OpenAsync();

            var result = await connection.QueryFirstAsync <Attend>(
                "DELETE FROM _attends WHERE student_id = @student AND course_id = @course",
                new { student = association.StudentId, course = association.CourseId });

            await connection.CloseAsync();
        }
示例#3
0
        public async Task <IActionResult> RemoveStudentFromCourse([FromServices] IAssociationRepository repository,
                                                                  [FromBody] StudentCourseAssociation association)
        {
            try
            {
                await repository.RemoveStudentFromCourse(association);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
示例#4
0
        public async Task <IActionResult> AddStudentToCourse([FromServices] IAssociationRepository repository,
                                                             [FromBody] StudentCourseAssociation association)
        {
            try
            {
                var result = await repository.AddStudentToCourse(association);

                return(Ok(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
        public ActionResult Edit(int id, StudentCourseAssociationViewModel studentCourseAssociationViewModel)
        {
            StudentCourseAssociation studentCourseAssociation = studentCourseAssociationViewModel.StudentCourseAssociation;

            try
            {
                studentCourseAssociationService.Edit(studentCourseAssociation);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(studentCourseAssociationViewModel));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            StudentCourseAssociation studentCourseAssociation = studentCourseAssociationService.Get(id);

            try
            {
                studentCourseAssociationService.Delete(studentCourseAssociation);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(View(studentCourseAssociation));
            }
        }
示例#7
0
        public async Task <Attend> AddStudentToCourse(StudentCourseAssociation association)
        {
            await using var connection =
                            new NpgsqlConnection(Environment.GetEnvironmentVariable("DATABASE"));

            await connection.OpenAsync();

            var result = await connection.QueryFirstAsync <Attend>(
                "INSERT INTO _attends(student_id, course_id) VALUES (@student, @course)",
                new { student = association.StudentId, course = association.CourseId });

            await connection.CloseAsync();

            return(result);
        }
示例#8
0
        public async Task RemoveStudentFromCourse(StudentCourseAssociation association)
        {
            if (await _dbContext.Students.FindAsync(association.StudentId) == null)
            {
                return;
            }

            if (await _dbContext.Courses.FindAsync(association.CourseId) == null)
            {
                return;
            }

            var result = await _dbContext.Attends.FirstAsync(attend =>
                                                             attend.StudentId == association.StudentId && attend.CourseId == association.CourseId);

            _dbContext.Entry(result).State = EntityState.Deleted;

            await _dbContext.SaveChangesAsync();
        }
示例#9
0
        public async Task <Attend> AddStudentToCourse(StudentCourseAssociation association)
        {
            if (await _dbContext.Students.FindAsync(association.StudentId) == null)
            {
                return(null);
            }

            if (await _dbContext.Courses.FindAsync(association.CourseId) == null)
            {
                return(null);
            }


            var result = await _dbContext.Attends.AddAsync(new Attend
            {
                StudentId = association.StudentId,
                CourseId  = association.CourseId
            });

            await _dbContext.SaveChangesAsync();

            return(result.Entity);
        }
        // GET: StudentCourseAssociation/Details/5
        public ActionResult Details(int id)
        {
            StudentCourseAssociation studentCourseAssociation = studentCourseAssociationService.Get(id);

            return(View(studentCourseAssociation));
        }