public async Task <IActionResult> UpdateQuestion(int id, [FromForm] QuestionCreateDTO questionCreateDTO) { try { var questionFromDb = await _repo.GetOneWithConditionTracking <Question>(q => q.Id == id); if (questionFromDb == null) { return(NotFound(new { Error = "Không tìm thấy câu hỏi" })); } _mapper.Map(questionCreateDTO, questionFromDb); if (questionCreateDTO.File != null) { if (!string.IsNullOrEmpty(questionFromDb.PublicId)) { var deleteResult = _helper.DeleteImage(questionFromDb.PublicId); if (deleteResult) { var uploadResult = _helper.UploadImage(questionCreateDTO.File); if (uploadResult != null) { questionFromDb.PublicId = uploadResult.PublicId; questionFromDb.PhotoUrl = uploadResult.PublicUrl; } } } } if (questionCreateDTO.Audio != null) { var uploadResult = await _dropBox.UploadFile(questionCreateDTO.Audio, "/Engrisk"); if (uploadResult != null) { questionFromDb.Audio = uploadResult.SharedUrl; } } if (await _repo.SaveAll()) { return(Ok()); } return(NoContent()); } catch (System.Exception e) { throw e; } }
public async Task <IActionResult> EditQuestion(int id, [FromForm] QuestionCreateDTO question) { var questionFromDb = await _repo.GetOneWithConditionTracking <Question>(question => question.Id == id); if (questionFromDb == null) { return(NotFound()); } _mapper.Map(question, questionFromDb); if (await _repo.SaveAll()) { return(Ok()); } else { return(NoContent()); } }
public async Task <IActionResult> CreateQuestion([FromForm] QuestionCreateDTO questionDTO) { var properties = new Dictionary <dynamic, dynamic>(); properties.Add("Content", questionDTO.Content); if (_repo.Exists <Question>(properties)) { return(Conflict()); } var question = _mapper.Map <Question>(questionDTO); if (questionDTO.File != null) { var result = _helper.UploadImage(questionDTO.File); if (result != null) { question.PhotoUrl = result.PublicUrl; question.PublicId = result.PublicId; } } if (questionDTO.Audio != null) { var uploadResult = await _dropBox.UploadFile(questionDTO.Audio, "/Engrisk"); if (uploadResult != null) { question.Audio = uploadResult.SharedUrl; } } _repo.Create(question); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Error on create question")); }
public IActionResult CreateNewQuestion([FromBody] QuestionCreateDTO newQuestion) { return(null); }