public Doctor createDoctor(Doctor doctor) { _dbContext.Doctor.Add(doctor); _dbContext.SaveChanges(); return(_dbContext.Doctor.Where(d => d.FirstName == doctor.FirstName && d.LastName == doctor.LastName && d.Email == doctor.Email) .FirstOrDefault()); }
public DoctorResponse AddDoctor(Doctor doctor) { doctorDbContext.Doctors.Add(doctor); doctorDbContext.SaveChanges(); return(new DoctorResponse { Email = doctor.Email, LastName = doctor.LastName, Name = doctor.FirstName }); }
public Doctor AddDoctor(Doctor doctor) { _doctorDbContext.Doctors.Add(new Doctor() { FirstName = doctor.FirstName, LastName = doctor.LastName, Email = doctor.Email }); return(_doctorDbContext.SaveChanges() == 1 ? doctor : null); }
public IActionResult AddDoctor(Doctor doctor) { try { _context.Doctors.Add(doctor); _context.SaveChanges(); return(Ok("Created a new doctor")); } catch (Exception e) { return(BadRequest(e)); } }
public Doctor AddDoctor(DoctorRequest doctorRequest) { var doctor = new Doctor { IdDoctor = doctorRequest.IdDoctor, FirstName = doctorRequest.FirstName, LastName = doctorRequest.LastName, Email = doctorRequest.Email }; context.Add(doctor); context.SaveChanges(); return(doctor); }
public bool AddDoctor(Doctor doctor) { try { _context.Doctors.Add(doctor); _context.SaveChanges(); return(true); } catch (Exception exc) { return(false); } }
public bool AddDoctor(Doctor doc) { _dbService.Add(doc); try { _dbService.SaveChanges(); return(true); }catch (Exception e) { return(false); } }
public IActionResult CreateDoctor(CreateDoctorRequest request) { var res = new Doctor { FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }; _context.Doctors.Add(res); _context.SaveChanges(); return(Ok(res)); }
public Doctor AddDoctor(Doctor doctorDto) { var doctor = new Doctor { FirstName = doctorDto.FirstName, LastName = doctorDto.LastName, Email = doctorDto.Email }; _context.Add(doctor); _context.SaveChanges(); return(doctor); }
public IActionResult AddDoctor(DoctorModel doctor) { try { if (doctor != null) { _context.Add(doctor); _context.SaveChanges(); return Ok("saved"); } return NotFound(); } catch { return BadRequest(); } }
public Doctor CreateDoctor(Doctor doctor) { var newDoctor = _context.AddAsync(doctor); _context.SaveChanges(); return(doctor); }
public ModifyDoctorResponse ModifyDoctor(ModifyDoctorRequest request) { var response = new ModifyDoctorResponse(); using (var doctorDbContext = new DoctorDbContext()) { var entity = doctorDbContext.Doctors.FirstOrDefault(item => item.IdDoctor == request.doctor.IdDoctor); if (entity != null) { entity.FirstName = request.doctor.FirstName; entity.LastName = request.doctor.LastName; entity.Email = request.doctor.Email; try { doctorDbContext.SaveChanges(); response.message = "UPDATE SUCCESSFULL"; } catch (Exception) { response.message = "UPDATE FAILED"; } } else { response.message = "There is no doctor with this index!"; } } return(response); }
public DeleteDoctorResponse DeleteDoctor(DeleteDoctorRequest request) { var response = new DeleteDoctorResponse(); using (var doctorDbContext = new DoctorDbContext()) { var doctorToDelete = doctorDbContext.Doctors.SingleOrDefault(doctor => doctor.IdDoctor.Equals(request.IdDoctor)); if (doctorToDelete != null) { try { doctorDbContext.Doctors.Remove(doctorToDelete); doctorDbContext.SaveChanges(); response.message = "Doctor " + request.IdDoctor + " deleted successful"; } catch (Exception) { response.message = "Doctor delete FAILED"; } } else { response.message = "There is no such a doctor to delete!"; } } return(response); }
public string addDoctor(Doctor doctor) { var res = _context.Doctor.Any(e => e.IdDoctor == doctor.IdDoctor); if (res == true) { // return BadRequest("There is a doctor with this id!"); throw new Exception("There is a doctor with this id!"); } else { _context.Doctor.Add(doctor); _context.SaveChanges(); //return Ok("Succesfully added!"); return("Succesfully added!"); } }
public IActionResult UpdateDoctor(Doctor doctor, int id) { var doctorUpdate = new Doctor { IdDoctor = id, FirstName = doctor.FirstName, LastName = doctor.LastName, Email = doctor.Email }; _context.Attach(doctorUpdate); _context.Entry(doctorUpdate).Property("FirstName").IsModified = true; _context.Entry(doctorUpdate).Property("LasttName").IsModified = true; _context.Entry(doctorUpdate).Property("Email").IsModified = true; _context.SaveChanges(); return(Ok(doctorUpdate)); }
public bool ModifyDoctor(DoctorRequest request) { var updatedRequest = UpdateDoctor(request); try { _context.Update(updatedRequest); _context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }
public IActionResult DeleteDoctor(int id) { var db = new DoctorDbContext(); var d1 = new Doctor() { IdDoctor = id }; db.Attach(d1); db.Remove(d1); db.SaveChanges(); return(Ok(d1)); }
public IActionResult UpdateDoctor(DoctorRequest request) { var db = new DoctorDbContext(); var d1 = new Doctor { IdDoctor = request.IdDoctor, FirstName = request.FirstName, LastName = request.LastName, Email = request.Email }; db.Attach(d1); db.SaveChanges(); return(Ok(d1)); }
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); }
private void Save() { _dbContext.SaveChanges(); }
public MsSqlService(DoctorDbContext doctorDbContext) { _doctorDbContext = doctorDbContext; _doctorDbContext.Doctors.Add(new Doctor() { FirstName = "Johnny", LastName = "Sins", Email = "*****@*****.**" }); _doctorDbContext.Doctors.Add(new Doctor() { FirstName = "Jack", LastName = "Sparrow", Email = "*****@*****.**" }); _doctorDbContext.Medicaments.Add(new Medicament() { Name = "Apap", Description = "Headache", Type = "Painkiller" }); _doctorDbContext.Medicaments.Add(new Medicament() { Name = "Ibuprom", Description = "Headache", Type = "Painkiller" }); _doctorDbContext.Patients.Add(new Patient() { FirstName = "Jacob", LastName = "Smith", BirthDate = DateTime.Parse("2000-10-10") }); _doctorDbContext.Patients.Add(new Patient() { FirstName = "Ahmad", LastName = "Opx", BirthDate = DateTime.Parse("2010-02-11") }); _doctorDbContext.Prescriptions.Add(new Prescription() { Date = DateTime.Parse("2000-10-10"), DueDate = DateTime.Today, IdDoctor = 1, IdPatient = 1 }); _doctorDbContext.Prescriptions.Add(new Prescription() { Date = DateTime.Parse("2010-10-10"), DueDate = DateTime.Today, IdDoctor = 2, IdPatient = 2 }); _doctorDbContext.PrescriptionMedicament.Add(new PrescriptionMedicament() { IdMedicament = 1, IdPrescription = 1, Details = "2 times a day", Dose = 1 }); _doctorDbContext.PrescriptionMedicament.Add(new PrescriptionMedicament() { IdMedicament = 2, IdPrescription = 2, Details = "3 times a day", Dose = 3 }); _doctorDbContext.SaveChanges(); }
public List <Doctor> SeedData() { /* Doctors */ _context.Doctors.Add(new Doctor { FirstName = "Greg", LastName = "House", Email = "*****@*****.**" }); _context.Doctors.Add(new Doctor { FirstName = "John", LastName = "Watson", Email = "*****@*****.**" }); /* Patients */ _context.Patients.Add(new Patient { FirstName = "Jan", LastName = "Kowalski", BirthDate = new DateTime(1990, 10, 1) }); _context.Patients.Add(new Patient { FirstName = "Very", LastName = "Sick", BirthDate = new DateTime(1994, 8, 13) }); /* Prescriptions */ _context.Prescriptions.Add(new Prescription { Date = new DateTime(2019, 6, 25), DueDate = new DateTime(2020, 6, 25), IdDoctor = 1, IdPatient = 1 }); _context.Prescriptions.Add(new Prescription { Date = new DateTime(2019, 6, 25), DueDate = new DateTime(2020, 6, 25), IdDoctor = 2, IdPatient = 1 }); _context.Prescriptions.Add(new Prescription { Date = new DateTime(2019, 6, 25), DueDate = new DateTime(2020, 6, 25), IdDoctor = 1, IdPatient = 2 }); /* Medicaments */ _context.Medicaments.Add(new Medicament { Name = "Med1", Description = "Med1", Type = "Med1" }); _context.Medicaments.Add(new Medicament { Name = "Med2", Description = "Med2", Type = "Med2" }); /* Prescription_Medicaments */ _context.Prescription_Medicaments.Add(new Prescription_Medicament { IdMedicament = 1, IdPrescription = 1, Details = "123" }); _context.Prescription_Medicaments.Add(new Prescription_Medicament { IdMedicament = 1, IdPrescription = 2, Details = "123" }); _context.Prescription_Medicaments.Add(new Prescription_Medicament { IdMedicament = 2, IdPrescription = 3, Details = "123" }); try { _context.SaveChanges(); } catch (DbUpdateException) { return(null); } return(GetDoctors()); }
public void AddDoctor(Doctor doctor) { _db.Add(doctor); _db.SaveChanges(); }
public void CreateDoctor(Doctor doctor) { _context.Doctor.Add(doctor); _context.SaveChanges(); }