public Response <DoctorDTO> Post(DoctorDTO doctorDTO) { try { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; doctorDTO.FirstName = textInfo.ToTitleCase(doctorDTO.FirstName); doctorDTO.LastName = textInfo.ToTitleCase(doctorDTO.LastName); doctorDTO.DisplayName = textInfo.ToTitleCase(doctorDTO.DisplayName); using (VDEntities entities = new VDEntities()) { // 1- send email to doctor UserEmail.DoctorEmail(doctorDTO); // 2- save User first User userDB = new User(); userDB.MobileNumber = doctorDTO.MobileNumber; userDB.Password = doctorDTO.Password; userDB.CountryCode = doctorDTO.CountryCode; userDB.UserType = "DOCTOR"; entities.Users.Add(userDB); entities.SaveChanges(); // 2- save Doctor Doctor doctorDB = Mapper.Map <Doctor>(doctorDTO); doctorDB.ValidUpto = null; doctorDB.UserID = userDB.ID; entities.Doctors.Add(doctorDB); entities.SaveChanges(); doctorDTO.ID = doctorDB.ID; //generate SMS and save it to the db UserSMS.DoctorSMS(doctorDTO); // 4- check if clinicDto exsist; then save clinic as well if (doctorDTO.ClinicDTO != null && !String.IsNullOrEmpty(doctorDTO.ClinicDTO.Name)) { doctorDTO.ClinicDTO.Name = textInfo.ToTitleCase(doctorDTO.ClinicDTO.Name); doctorDTO.ClinicDTO.DoctorID = doctorDB.ID; Clinic clinicDB = Mapper.Map <Clinic>(doctorDTO.ClinicDTO); entities.Clinics.Add(clinicDB); entities.SaveChanges(); doctorDTO.ClinicDTO.ID = clinicDB.ID; } } return(new Response <DoctorDTO>(true, null, doctorDTO)); } catch (Exception ex) { return(new Response <DoctorDTO>(false, GetMessageFromExceptionObject(ex), null)); } }