public async Task <IActionResult> New(InputModel input) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var exam = new ExamInput { Title = input.Title, // use automapper !!! Opens = input.Opens, Closes = input.Closes, Duration = input.Duration, AcceptAfterClosing = input.AcceptAfterClosing, AcceptExpiredTime = input.AcceptExpiredTime, RandomVariant = input.RandomVariant, QuestionsPerVariant = input.QuestionsPerVariant, AnswersPerQuestion = input.AnswersPerQuestion, CourseId = input.CourseId, AuthorId = userId, Questions = input.Question?.Select(q => new QuestionInput { Content = q.Content, Answers = q.Answers.Select(a => new AnswerInput { Content = a.Content, Points = a.Points, IsCorrect = a.IsCorrect, }), }).ToList(), }; var examId = await this.examService .CreateAsync(exam); return(this.RedirectToAction(nameof(this.Details), new { id = examId })); }
public async void Create(ICloseable window) { try { if (HasErrors) { return; } ExamInput input = new ExamInput() { CategoryId = Category.Id, Name = Name, Price = Price, CurrencyId = Currency, ReferenceNo = ReferenceNo }; ExamDto examDto = await(NewExam ?AppService.CreateAsync(input): AppService.UpdateAsync(Id, input)); if (NewExam) { EventAggregator.GetEvent <ExamAddedEvent>().Publish(examDto); } else { EventAggregator.GetEvent <ExamUpdatedEvent>().Publish(examDto); } window.Close(); } catch (SqliteException sqlEx) { ErrorText = sqlEx.Message; } catch (BusinessException busEx) { ErrorText = busEx.Message; } }
public async Task <string> CreateAsync(ExamInput examInput) { var exam = AutoMapperConfig.MapperInstance.Map <Exam>(examInput); await this.examsRepository.AddAsync(exam); await this.examsRepository.SaveChangesAsync(); await this.notificationService .CreateAsync("created new exam", $"classroom/exams/start/{exam.Id}", 1, null, exam.AuthorId, exam.CourseId); return(exam.Id); }