public async Task <Result> UpdateAsync(int patientId, InsertPatientDto insertPatientDto) { var patient = await _repository.TableNoTracking .Where(x => x.Id == patientId) .FirstOrDefaultAsync(); patient.Email = insertPatientDto.Email; patient.IdentityNumber = insertPatientDto.IdentityNumber; var result = await _repository.UpdateAsync(patient); if (!result.Success) { return(new ErrorResult()); } var person = await _personRepo.GetAsync(x => x.Id == patient.PersonId); person.FirstName = insertPatientDto.FirstName; person.LastName = insertPatientDto.LastName; person.Gsm = insertPatientDto.Gsm; return(await _personRepo.UpdateAsync(person)); }
public async Task <IActionResult> Update([FromQuery] int patientId, [FromBody] InsertPatientDto patientDto) { return(Ok(await _patientService.UpdateAsync(patientId, patientDto))); }
public async Task <DataResult <GetPatientDto> > InsertAsync(InsertPatientDto insertPatientDto) { //System will automatically create a random password with size 6. var randomPass = RandomHelper.Mixed(6); HashingHelper.CreatePasswordHash(randomPass, out var passwordHash, out var passwordSalt); var patient = new Patient { IdentityNumber = insertPatientDto.IdentityNumber, Email = insertPatientDto.Email, PatientDiseases = new List <PatientDisease>(), IsActive = true, Age = insertPatientDto.Age, Weight = insertPatientDto.Weight, Height = insertPatientDto.Height, Person = new Person { FirstName = insertPatientDto.FirstName, LastName = insertPatientDto.LastName, UserName = insertPatientDto.IdentityNumber, Gsm = insertPatientDto.Gsm, PersonType = PersonType.Patient, CreatedAt = DateTime.Now, CreatedUserName = _userService.FullName, PasswordHash = passwordHash, PasswordSalt = passwordSalt, RefreshToken = RandomHelper.Mixed(32) }, }; var doctor = await _doctorRepo.TableNoTracking.Where(x => x.PersonId == _userService.PersonId) .FirstOrDefaultAsync(); await _repository.InsertAsync(patient); await _doctorPatientRepo.InsertAsync(new DoctorPatient { DoctorId = doctor.Id, PatientId = patient.Id }); await _smsHelper.SendAsync(new List <string> { patient.Person.Gsm }, "Welcome to the YEDITEPE HOSPITAL \nYou are registered to patracker as Patient by " + _userService.FullName + " \nLogin to the system with your ID \nYour password is " + randomPass); var result = await _repository.TableNoTracking.Where(x => x.PersonId == patient.Person.Id) .Include(x => x.Person) .FirstOrDefaultAsync(); return(new SuccessDataResult <GetPatientDto>(new GetPatientDto { IdentityNumber = result.IdentityNumber, FirstName = result.Person.FirstName, LastName = result.Person.LastName, Email = result.Email, Gsm = result.Person.Gsm, Age = result.Age, Weight = result.Weight, Height = result.Height, HealthScore = _patientAnswerService.GetTotalScoreOfPatient(result.Id), Diseases = new List <string>() })); }
public async Task <IActionResult> Post([FromBody] InsertPatientDto dto) { return(Ok(await _patientService.InsertAsync(dto))); }