public async Task <IActionResult> PostConfirmatoryTests([FromBody] AddHivReConfirmatoryTestsCommand addHivReConfirmatoryTestsCommand) { var response = await _mediator.Send(addHivReConfirmatoryTestsCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }
public async Task <Result <HivReConfirmatoryTestsResponse> > Handle(AddHivReConfirmatoryTestsCommand request, CancellationToken cancellationToken) { using (_unitOfWork) { try { var reConfirmatoryTests = await _unitOfWork.Repository <HIVReConfirmatoryTest>() .Get(x => x.PersonId == request.PersonId).ToListAsync(); if (reConfirmatoryTests.Count > 0) { reConfirmatoryTests[0].DeleteFlag = true; _unitOfWork.Repository <HIVReConfirmatoryTest>().Update(reConfirmatoryTests[0]); await _unitOfWork.SaveAsync(); } HIVReConfirmatoryTest hivReConfirmatory = new HIVReConfirmatoryTest() { PersonId = request.PersonId, TypeOfTest = request.TypeOfTest, TestResult = request.TestResult, TestResultDate = request.TestResultDate, DeleteFlag = false, CreatedBy = request.CreatedBy, CreateDate = DateTime.Now }; await _unitOfWork.Repository <HIVReConfirmatoryTest>().AddAsync(hivReConfirmatory); await _unitOfWork.SaveAsync(); return(Result <HivReConfirmatoryTestsResponse> .Valid(new HivReConfirmatoryTestsResponse() { Message = "Successfully saved patient hiv-reconfirmatory tests" })); } catch (Exception e) { Log.Error($"An error occurred while saving patient hiv reconfirmatory tests " + e.Message + $" for personid: {request.PersonId}"); return(Result <HivReConfirmatoryTestsResponse> .Invalid($"An error occurred while saving patient hiv reconfirmatory tests " + e.Message + $" for personid: {request.PersonId}")); } } throw new System.NotImplementedException(); }