public Doctor Create(string userId, CreateDoctorDTO createDoctorDTO) { Doctor doctor = Mapper.Map <Doctor>(createDoctorDTO); doctor.UserId = userId; doctor.IsAccepted = false; var createdDoctor = TheUnitOfWork.DoctorRepo.Insert(doctor); TheUnitOfWork.SaveChanges(); return(createdDoctor); }
public async Task <IActionResult> RegisterDoctor(CreateDoctorDTO registerDoctorDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } bool isUsernameExist = await _accountAppService.checkUsernameExist(registerDoctorDTO.UserName); if (isUsernameExist) { return(BadRequest(new Response { Message = "Username already exist" })); } bool isEmailExist = await _accountAppService.checkEmailExist(registerDoctorDTO.Email); if (isEmailExist) { return(BadRequest(new Response { Message = "Email already exist" })); } try { registerDoctorDTO.IsDoctor = true; ApplicationUserIdentity registerUser = await _accountAppService.Register(registerDoctorDTO); await _accountAppService.AssignToRole(registerUser.Id, UserRoles.Doctor); _doctorAppService.Create(registerUser.Id, registerDoctorDTO); _generalAppService.CommitTransaction(); return(Ok(new Response { Message = "Doctor created successfully" })); } catch (Exception ex) { _generalAppService.RollbackTransaction(); return(BadRequest(new Response { Message = ex.Message })); } }
public IActionResult CreateDoctor(CreateDoctorDTO createDoctor) { var response = _context.CreateDoctor(createDoctor); return(Created("Doctor has been added", response)); }