public AddDoctorResponse add(AddDoctorRequest request) { try { var response = new AddDoctorResponse(); var bc = new DoctorComponent(); response.Result = bc.Add(request.Doctor); return(response); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
public AddDoctorResponse AddDoctor(AddDoctorRequest request) { var response = new AddDoctorResponse(); using (var doctorContext = new DoctorDbContext()) { doctorContext.Doctors.Add(request.doctor); try { doctorContext.SaveChanges(); response.message = "INSERT SUCCESSFUL"; } catch (Exception) { response.message = "INSERT FAILED"; } } return(response); }
public AddDoctorResponse AddDoctor(AddDoctorRequest request) { var d = new Doctor { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }; _context.Doctor.Add(d); _context.SaveChanges(); var res = new AddDoctorResponse { IdDoctor = d.IdDoctor, FirstName = d.FirstName, LastName = d.LastName, Email = d.Email }; return(res); }