public async Task <BasexResponse <MaterialAnswer> > CreateAsync(MaterialAnswer materialAnswer) { try { materialAnswer.CreationTime = DateTime.UtcNow; await _materialAnswerDal.AddAsync(materialAnswer); await _unitOfWork.CompleteAsync(); return(new BasexResponse <MaterialAnswer>(materialAnswer)); } catch (Exception ex) { return(new BasexResponse <MaterialAnswer>(ex.Message)); } }
public async Task <IActionResult> GivePoint([FromBody] MaterialAnswerUpdateResource model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MaterialAnswer materialAnswer = _mapper.Map <MaterialAnswerUpdateResource, MaterialAnswer>(model); var materialAnswerResponse = await _materialAnswerService.UpdateAsync(materialAnswer); if (!materialAnswerResponse.Success) { return(BadRequest(materialAnswerResponse.Message)); } return(Ok(materialAnswerResponse.Extra)); }
public async Task <IActionResult> Create([FromBody] MaterialAnswerResource model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = Int32.Parse((HttpContext.User.FindFirst("id").Value)); MaterialAnswer materialAnswer = _mapper.Map <MaterialAnswerResource, MaterialAnswer>(model); materialAnswer.UserId = userId; var materialAnswerResponse = await _materialAnswerService.CreateAsync(materialAnswer); if (!materialAnswerResponse.Success) { return(BadRequest(materialAnswerResponse.Message)); } return(Ok(materialAnswerResponse.Extra)); }
public async Task <BasexResponse <MaterialAnswer> > UpdateAsync(MaterialAnswer materialAnswer) { try { var resultMaterialAnswer = await _materialAnswerDal.FindAsync(ma => ma.MaterialId == materialAnswer.MaterialId && ma.UserId == materialAnswer.UserId); if (resultMaterialAnswer == null) { return(new BasexResponse <MaterialAnswer>("Student has not done yet")); } resultMaterialAnswer.Score = materialAnswer.Score; var updatedMaterialAnswer = await _materialAnswerDal.UpdateAsync(resultMaterialAnswer); await _unitOfWork.CompleteAsync(); return(new BasexResponse <MaterialAnswer>(resultMaterialAnswer)); } catch (Exception ex) { return(new BasexResponse <MaterialAnswer>(ex.Message)); } }