public async Task <Result <UpdatePatientFamilyPlanningResponse> > Handle(UpdatePatientFamilyPlanningCommand request, CancellationToken cancellationToken) { using (_maternityUnitOfWork) { try { var familyPlanning = await _maternityUnitOfWork.Repository <PatientFamilyPlanning>() .FindByIdAsync(request.Id); if (familyPlanning != null) { familyPlanning.FamilyPlanningStatusId = request.FamilyPlanningStatusId; familyPlanning.ReasonNotOnFPId = request.ReasonNotOnFPId; _maternityUnitOfWork.Repository <PatientFamilyPlanning>().Update(familyPlanning); await _maternityUnitOfWork.SaveAsync(); return(Result <UpdatePatientFamilyPlanningResponse> .Valid(new UpdatePatientFamilyPlanningResponse() { Message = "Successfully update familyplanning" })); } else { Log.Error($"Family Planning with id: {request.Id} could not be found"); return(Result <UpdatePatientFamilyPlanningResponse> .Invalid($"Family Planning with id: {request.Id} could not be found")); } } catch (Exception e) { Log.Error($"Error updating PatientFamilyPlanning with id: {request.Id}"); return(Result <UpdatePatientFamilyPlanningResponse> .Invalid($"Error updating PatientFamilyPlanning with id: {request.Id}")); } } }
public async Task <IActionResult> UpdateFamilyPlanning([FromBody] UpdatePatientFamilyPlanningCommand updatePatientFamilyPlanningCommand) { if (!ModelState.IsValid) { return(BadRequest(updatePatientFamilyPlanningCommand)); } var response = await _mediator.Send(updatePatientFamilyPlanningCommand, Request.HttpContext.RequestAborted); if (response.IsValid) { return(Ok(response.Value)); } return(BadRequest(response)); }