Example #1
0
        /// <summary>
        /// Method to update class exam - SS
        /// </summary>
        /// <param name="updateClassExam">class exam</param>
        /// <param name="loggedInUser">logged in user</param>
        /// <returns>response</returns>
        public async Task <ClassExamResponse> UpdateClassExamResponseAsync(UpdateClassExamAc updateClassExam, ApplicationUser loggedInUser)
        {
            var subjectIds   = updateClassExam.ClassExamSubjectMappings.Select(x => x.SubjectId).Distinct().ToList();
            var subjectCount = await _iMSDbContext.InstituteSubjects.CountAsync(x => subjectIds.Contains(x.Id));

            if (subjectIds.Count != subjectCount)
            {
                return new ClassExamResponse()
                       {
                           HasError = true, Message = "Subject not found", ErrorType = ClassExamResponseType.SubjectId
                       }
            }
            ;
            else
            {
                var instituteId = await _instituteUserMappingHelperService.GetUserCurrentSelectedInstituteIdAsync(loggedInUser.Id, true);

                var classExam = await _iMSDbContext.ClassExams.FirstOrDefaultAsync(x => x.Id == updateClassExam.ClassExamId && x.Exam.InstituteId == instituteId);

                if (classExam == null)
                {
                    return new ClassExamResponse()
                           {
                               HasError = true, Message = "Class exam not found", ErrorType = ClassExamResponseType.ClassExamId
                           }
                }
                ;
                else
                {
                    classExam.TotalAttendanceDays = updateClassExam.TotalAttendanceDays;

                    classExam.UpdatedById = loggedInUser.Id;
                    classExam.UpdatedOn   = DateTime.UtcNow;
                    var subjects = await _iMSDbContext.ClassExamSubjectMappings.Where(x => x.ClassExamId == classExam.Id).ToListAsync();

                    _iMSDbContext.ClassExamSubjectMappings.RemoveRange(subjects);
                    _iMSDbContext.ClassExams.Update(classExam);
                    await _iMSDbContext.SaveChangesAsync();

                    List <ClassExamSubjectMapping> classExamSubjects = new List <ClassExamSubjectMapping>();
                    foreach (var subject in updateClassExam.ClassExamSubjectMappings)
                    {
                        classExamSubjects.Add(new ClassExamSubjectMapping()
                        {
                            ClassExamId = classExam.Id,
                            Content     = subject.Content,
                            CreatedOn   = DateTime.UtcNow,
                            EndTime     = subject.EndTime,
                            MaxScore    = subject.MaxScore,
                            MinScore    = subject.MinScore,
                            Remark      = subject.Remark,
                            StartDate   = subject.StartDate,
                            StartTime   = subject.StartTime,
                            SubjectId   = subject.SubjectId
                        });
                    }
                    _iMSDbContext.ClassExamSubjectMappings.AddRange(classExamSubjects);
                    await _iMSDbContext.SaveChangesAsync();

                    return(new ClassExamResponse()
                    {
                        HasError = false, Message = "Class exam detail updated successfully"
                    });
                }
            }
        }
Example #2
0
        public async Task <IActionResult> UpdateClassExamResponseAsync([FromBody] UpdateClassExamAc updateClassExam)
        {
            var loggedInUser = await _userManager.FindByNameAsync(User.Identity.Name);

            return(Ok(await _markManagementRepository.UpdateClassExamResponseAsync(updateClassExam, loggedInUser)));
        }