Пример #1
0
        public async Task <ServiceResponse <object> > SubmitQuiz(List <QuizSubmissionDto> model)
        {
            List <QuizSubmission> ListToAdd = new List <QuizSubmission>();

            foreach (var item in model)
            {
                var TrueAnswers = (from q in _context.QuizQuestions
                                   join ans in _context.QuizAnswers
                                   on q.Id equals ans.QuestionId
                                   where ans.IsTrue == true &&
                                   q.Id == item.QuestionId &&
                                   q.QuizId == item.QuizId
                                   select ans).ToList();

                var submission = new QuizSubmission
                {
                    QuizId     = item.QuizId,
                    QuestionId = item.QuestionId,
                    AnswerId   = item.AnswerId,
                    //IsCorrect = TrueAnswers.Select(m => m.Id).Contains(Convert.ToInt32(item.AnswerId)) ? true : false,
                    Description     = item.Description,
                    CreatedDateTime = DateTime.UtcNow,
                    UserId          = _LoggedIn_UserID
                };
                if (TrueAnswers.Count() == 1)
                {
                    submission.IsCorrect   = TrueAnswers.Select(m => m.Id).Contains(Convert.ToInt32(item.AnswerId)) ? true : false;
                    submission.ResultMarks = submission.IsCorrect == true?_context.QuizQuestions.FirstOrDefault(m => m.QuizId == item.QuizId && m.Id == item.QuestionId).Marks.Value : 0;
                }
                else if (TrueAnswers.Count() == 2)
                {
                    //int ContainCount = TrueAnswers.Where(m => m.Id == Convert.ToInt32(item.AnswerId)).Count();
                    submission.IsCorrect = TrueAnswers.Select(m => m.Id).Contains(Convert.ToInt32(item.AnswerId)) ? true : false;
                    double set = _context.QuizQuestions.FirstOrDefault(m => m.QuizId == item.QuizId && m.Id == item.QuestionId).Marks.Value / 2;
                    submission.ResultMarks = submission.IsCorrect == true ? set : 0;
                }

                ListToAdd.Add(submission);
            }

            await _context.QuizSubmissions.AddRangeAsync(ListToAdd);

            await _context.SaveChangesAsync();

            var toCreateTrans = new StudentActivityTransaction
            {
                StudentId       = _LoggedIn_UserID,
                Value           = _LoggedIn_UserName + " you submit a quiz at " + DateFormat.ToDateTime(DateTime.UtcNow),
                Details         = "",
                UpdatedDateTime = DateTime.UtcNow
            };
            await _context.StudentActivityTransactions.AddAsync(toCreateTrans);

            await _context.SaveChangesAsync();

            _serviceResponse.Success = true;
            _serviceResponse.Data    = CustomMessage.Added;
            return(_serviceResponse);
        }
Пример #2
0
        public async Task <ServiceResponse <object> > SubmitAssignment(SubmitAssignmentDtoForAdd model)
        {
            var objToCreate = new ClassSectionAssigmentSubmission
            {
                ClassSectionAssignmentId = model.AssignmentId,
                Description     = model.Description,
                StudentId       = _LoggedIn_UserID,
                CreatedDatetime = DateTime.UtcNow,
            };

            if (model.files != null && model.files.Count() > 0)
            {
                for (int i = 0; i < model.files.Count(); i++)
                {
                    var dbPath = _filesRepository.SaveFile(model.files[i]);
                    if (string.IsNullOrEmpty(objToCreate.SubmittedMaterial))
                    {
                        objToCreate.SubmittedMaterial = objToCreate.SubmittedMaterial + dbPath;
                    }
                    else
                    {
                        objToCreate.SubmittedMaterial = objToCreate.SubmittedMaterial + "||" + dbPath;
                    }
                }
            }

            await _context.ClassSectionAssigmentSubmissions.AddAsync(objToCreate);

            await _context.SaveChangesAsync();

            var toCreateTrans = new StudentActivityTransaction
            {
                StudentId       = _LoggedIn_UserID,
                Value           = _LoggedIn_UserName + " you submit an assignment at " + DateFormat.ToDateTime(DateTime.UtcNow),
                Details         = "",
                UpdatedDateTime = DateTime.UtcNow
            };
            await _context.StudentActivityTransactions.AddAsync(toCreateTrans);

            await _context.SaveChangesAsync();

            _serviceResponse.Success = true;
            _serviceResponse.Message = CustomMessage.Added;
            return(_serviceResponse);
        }