public async Task Create(CreateMCQuestionDto dto) { var mcq = _mapper.Map <MCQuestionDbEntity>(dto); if (dto.AttachmentURL != null) { mcq.AttachmentURL = await _fileService.SaveFile(dto.AttachmentURL, "Attachments"); await _DB.MCQustions.AddAsync(mcq); } else { _DB.MCQustions.Add(mcq); } _DB.SaveChanges(); }
public IActionResult Create(CreateMCQuestionDto dto) { List <string> options = new List <string>() { dto.A, dto.B, dto.C, dto.D }; if (ModelState.IsValid) { if (!options.Contains(dto.CorrectAnswer)) { ViewBag.ErrorMessage = "Correcr Answer should match one of the options"; return(View(dto)); } else { _service.Create(dto); return(Redirect("~/Quiz/Questions?Id=" + (dto.QuizId))); } } return(View(dto)); }
public IActionResult Create([FromForm] CreateMCQuestionDto dto) { _service.Create(dto); return(Ok(GetResponse())); }