public async Task <ActionResult> CreateDoctor([FromBody] DoctorModel doctor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, doctor.Password); var instance = Doctor.Create(doctor.FirstName, doctor.LastName, doctor.Email, passwordHash, doctor.PhoneNumber, doctor.Description, doctor.Speciality, doctor.Hospital, doctor.City, doctor.Address); try { var newDoctor = await _repository.AddAsync(instance); if (newDoctor == null) { return(BadRequest(new ApiResponse { Status = false })); } return(CreatedAtRoute("GetDoctorRoute", new { id = newDoctor.DoctorId }, new ApiResponse { Status = true, Doctor = newDoctor })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }
public async Task <ActionResult> CreatePatient([FromBody] PatientModel patient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, patient.Password); string ninHash = PasswordHashMd5.GetMd5Hash(md5Hash, patient.NIN); var instance = Patient.Create(ninHash, patient.FirstName, patient.LastName, patient.Email, passwordHash, patient.City, patient.Country, patient.Birthdate, patient.PhoneNumber, null); try { var newPatient = await _repository.AddAsync(instance); if (newPatient == null) { return(BadRequest(new ApiResponse { Status = false })); } return(CreatedAtRoute("GetPatientRoute", new { id = newPatient.PatientId }, new ApiResponse { Status = true, Patient = newPatient })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }
public async Task <ActionResult> UpdateDoctor(Guid id, [FromBody] DoctorModel doctor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, doctor.Password); var instance = await _repository.GetByIdAsync(id); try { instance.Update(doctor.FirstName, doctor.LastName, doctor.Email, passwordHash, doctor.PhoneNumber, doctor.Description, doctor.Speciality, doctor.Hospital, doctor.City, doctor.Address); var status = await _repository.UpdateAsync(instance); if (!status) { return(BadRequest(new ApiResponse { Status = false })); } return(Ok(new ApiResponse { Status = true, Doctor = instance })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }
public async Task <ActionResult> DoctorAccount([FromBody] CredentialsModel doctorCredentialsModel) { try { MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, doctorCredentialsModel.Password); string doctorDin = PasswordHashMd5.GetMd5Hash(md5Hash, doctorCredentialsModel.DIN); string[] includes = { }; var doctorsList = await _repositoryDoctor.GetAllAsync(includes); foreach (var doctor in doctorsList) { if (doctor.DIN == doctorDin && doctor.Password == passwordHash) { var requestAt = DateTime.Now; var expiresIn = requestAt + TokenAuthOption.ExpiresSpan; var token = GenerateToken(expiresIn); return(Json(new RequestResult { State = RequestState.Success, Data = new { requertAt = requestAt, expiresIn = TokenAuthOption.ExpiresSpan.TotalSeconds, tokeyType = TokenAuthOption.TokenType, accessToken = token, user_id = doctor.DoctorId, user_password = doctor.Password, user_email = doctor.Email, isDoctor = true } })); } } } catch { return(Json(new RequestResult { State = RequestState.Failed })); } return(Json(new RequestResult { State = RequestState.Failed })); }
public async Task <ActionResult> UpdatePatient(Guid id, [FromBody] PatientModel patient, [FromHeader(Name = "Authorization")] string value) { var token = new JwtSecurityTokenHandler().ReadJwtToken(value); var issuer = token.Claims.First(claim => claim.Type == "iss").Value; var audience = token.Claims.First(claim => claim.Type == "aud").Value; if (issuer != "MyIssuer" || audience != "MyAudience") { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, patient.Password); var instance = await _repository.GetByIdAsync(id); try { instance.Update(patient.NIN, patient.FirstName, patient.LastName, patient.Email, passwordHash, patient.City, patient.Country, patient.Birthdate, patient.PhoneNumber); var status = await _repository.UpdateAsync(instance); if (!status) { return(BadRequest(new ApiResponse { Status = false })); } return(Ok(new ApiResponse { Status = true, Patient = instance })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }
public async Task <ActionResult> PacientAccount([FromBody] CredentialsModel patientCredetialsModel) { try { MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, patientCredetialsModel.Password); string[] includes = { "Appointments", "Feedbacks", "PatientHistories" }; var patientList = await _repositoryPatient.GetAllAsync(null); foreach (var patient in patientList) { if (patient.Email == patientCredetialsModel.Email && patient.Password == passwordHash) { var requestAt = DateTime.Now; var expiresIn = requestAt + TokenAuthOption.ExpiresSpan; var token = GenerateToken(expiresIn); return(Json(new RequestResult { State = RequestState.Success, Data = new { requertAt = requestAt, expiresIn = TokenAuthOption.ExpiresSpan.TotalSeconds, tokeyType = TokenAuthOption.TokenType, accessToken = token, user_id = patient.PatientId } })); } } } catch { return(Json(new RequestResult { State = RequestState.Failed })); } return(Json(new RequestResult { State = RequestState.Failed })); }
public async Task <ActionResult> UpdateDoctor(Guid id, [FromBody] DoctorModel doctor, [FromHeader(Name = "Authorization")] string value) { var token = new JwtSecurityTokenHandler().ReadJwtToken(value); var issuer = token.Claims.First(claim => claim.Type == "iss").Value; var audience = token.Claims.First(claim => claim.Type == "aud").Value; if (issuer != "MyIssuer" || audience != "MyAudience") { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, doctor.Password); var instance = await _repository.GetByIdAsync(id); try { instance.Update(doctor.DIN, doctor.FirstName, doctor.LastName, doctor.Email, passwordHash, doctor.PhoneNumber, doctor.Description, doctor.Speciality, doctor.Hospital, doctor.City, doctor.Country, doctor.Address, doctor.IsMale); var status = await _repository.UpdateAsync(instance); if (!status) { return(BadRequest(new ApiResponse { Status = false })); } return(Ok(new ApiResponse { Status = true, Doctor = instance })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }
public async Task <ActionResult> UpdatePatient(Guid id, [FromBody] PatientModel patient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } MD5 md5Hash = MD5.Create(); string passwordHash = PasswordHashMd5.GetMd5Hash(md5Hash, patient.Password); var instance = await _repository.GetByIdAsync(id); try { instance.Update(patient.FirstName, patient.LastName, patient.Email, passwordHash, patient.City, patient.Birthdate, patient.PhoneNumber); var status = await _repository.UpdateAsync(instance); if (!status) { return(BadRequest(new ApiResponse { Status = false })); } return(Ok(new ApiResponse { Status = true, Patient = instance })); } catch { return(BadRequest(new ApiResponse { Status = false })); } }