Beispiel #1
0
        public async Task <IActionResult> Put([FromODataUri] int assignmentId, [FromODataUri] int id, [FromBody] AssignmentTask assignmentTask)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != assignmentTask.Id || assignmentId != assignmentTask.AssignmentId)
            {
                return(BadRequest());
            }

            _context.Entry(assignmentTask).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AssignmentTaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <IActionResult> Put([FromODataUri] int id, [FromBody] Department department)
        {
            if (id != department.Id)
            {
                return(BadRequest());
            }

            _context.Entry(department).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Put([FromODataUri] int courseInfoId, [FromODataUri] int id, [FromBody] LearningOutcome outcome)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != outcome.Id || courseInfoId != outcome.CourseInfoId)
            {
                return(BadRequest());
            }

            _context.Entry(outcome).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LearningOutcomeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #4
0
        public async Task <ActionResult <ImportExcelDTO> > Import(ImportExcelDTO payload)
        {
            foreach (var(studentId, studentResult) in payload.StudentResults)
            {
                var student = new Student
                {
                    Id       = studentId,
                    FullName = studentResult.Name
                };

                var courseResult = new CourseResult
                {
                    CourseId  = payload.CourseId,
                    StudentId = studentId,
                };

                foreach (var(assignmentId, assignmentTaskResults) in studentResult.AssignmentTaskResults)
                {
                    var assignmentResult = new AssignmentResult
                    {
                        AssignmentId = assignmentId,
                    };

                    foreach (var(assignmentTaskId, grade) in assignmentTaskResults)
                    {
                        var assignmentTaskResult = new AssignmentTaskResult
                        {
                            AssignmentTaskId = assignmentTaskId,
                            Grade            = grade
                        };

                        assignmentResult.AssignmentTaskResults.Add(assignmentTaskResult);
                    }

                    courseResult.AssignmentResults.Add(assignmentResult);
                }

                var existingStudent = await _context.Students.FindAsync(student.Id);

                if (existingStudent == null)
                {
                    _context.Students.Add(student);
                }
                else
                {
                    _context.Entry(existingStudent).CurrentValues.SetValues(student);
                }

                var existingCourseResult = await _context.CourseResults.FindAsync(courseResult.Id);

                if (existingCourseResult == null)
                {
                    _context.CourseResults.Add(courseResult);
                }
                else
                {
                    _context.Entry(existingCourseResult).CurrentValues.SetValues(courseResult);
                }
            }

            await _context.SaveChangesAsync();

            return(NoContent());
        }