public async Task <OutputResponse> Add(PatientSymptomDTO symptom) { var isFound = await _context.PatientSymptoms.AnyAsync(x => x.SymptomName.ToLower() == symptom.SymptomName.ToLower()); if (isFound) { return(new OutputResponse { IsErrorOccured = true, Message = "Symptom name already exist, duplicates not allowed" }); } var mappedPatientStatus = new AutoMapperHelper <PatientSymptomDTO, PatientSymptoms>().MapToObject(symptom); mappedPatientStatus.RowAction = "I"; mappedPatientStatus.DateCreated = DateTime.UtcNow; await _context.PatientSymptoms.AddAsync(mappedPatientStatus); await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.AddNewSuccess }); }
public async Task <OutputResponse> Update(PatientSymptomDTO symptom) { var symptomToUpdate = await _context.PatientSymptoms.FirstOrDefaultAsync(x => x.SymptomId.Equals(symptom.SymptomId)); if (symptomToUpdate == null) { return(new OutputResponse { IsErrorOccured = true, Message = "Symptom specified does not exist, update cancelled" }); } //update details symptomToUpdate.SymptomName = symptom.SymptomName; symptomToUpdate.IsAvailableForRegistration = symptom.IsAvailableForRegistration; symptomToUpdate.ExternalReferenceNumber = symptom.ExternalReferenceNumber; symptomToUpdate.RowAction = "U"; symptomToUpdate.ModifiedBy = symptom.CreatedBy; symptomToUpdate.DateModified = DateTime.UtcNow; await _context.SaveChangesAsync(); return(new OutputResponse { IsErrorOccured = false, Message = MessageHelper.UpdateSuccess }); }
public async Task <IActionResult> Update([FromBody] PatientSymptomDTO symptom) { var outputHandler = await _service.Update(symptom); if (outputHandler.IsErrorOccured) { return(BadRequest(outputHandler.Message)); } return(Ok(outputHandler.Message)); }
private async Task <PatientSymptomDTO> GetPatientSymptom(int symptomId) { string url = $"{PatientsApiUrl}Symptoms/GetById?symptomId={symptomId}"; var PatientSymptom = new PatientSymptomDTO(); var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Get(accessToken, url); if (response.StatusCode == HttpStatusCode.OK) { PatientSymptom = response.ContentAsType <PatientSymptomDTO>(); } else { ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(PatientSymptom); }
public async Task <IActionResult> Edit([Bind] PatientSymptomDTO patientSymptom) { string url = $"{PatientsApiUrl}Symptoms/Update"; var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Put(accessToken, url, patientSymptom); if (response.StatusCode == HttpStatusCode.OK) { AppContextHelper.SetToastMessage("Patient symptom has been successfully updated", MessageType.Success, 1, Response); return(RedirectToAction(nameof(Index))); } else { AppContextHelper.SetToastMessage("Failed to update patient symptom", MessageType.Danger, 1, Response); ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(View(patientSymptom)); }
public async Task <IActionResult> VerifyDelete(int symptomId) { string url = $"{PatientsApiUrl}Symptoms/Delete?symptomId={symptomId}"; var PatientSymptom = new PatientSymptomDTO(); var accessToken = await HttpContext.GetTokenAsync("access_token"); var response = await HttpRequestFactory.Delete(accessToken, url); if (response.StatusCode == HttpStatusCode.OK) { AppContextHelper.SetToastMessage("Patient symptom has been successfully deleted", MessageType.Success, 1, Response); return(RedirectToAction(nameof(Index))); } else { AppContextHelper.SetToastMessage("Failed to delete patient symptom", MessageType.Danger, 1, Response); ModelState.AddModelError("", HttpResponseHandler.Process(response)); } return(View(await GetPatientSymptom(symptomId))); }