Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
        public DoctorResponse AddDoctor(Doctor doctor)
        {
            doctorDbContext.Doctors.Add(doctor);
            doctorDbContext.SaveChanges();

            return(new DoctorResponse {
                Email = doctor.Email, LastName = doctor.LastName, Name = doctor.FirstName
            });
        }
Ejemplo n.º 3
0
 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);
 }
Ejemplo n.º 4
0
 public IActionResult AddDoctor(Doctor doctor)
 {
     try
     {
         _context.Doctors.Add(doctor);
         _context.SaveChanges();
         return(Ok("Created a new doctor"));
     }
     catch (Exception e) { return(BadRequest(e)); }
 }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public bool AddDoctor(Doctor doctor)
 {
     try
     {
         _context.Doctors.Add(doctor);
         _context.SaveChanges();
         return(true);
     } catch (Exception exc)
     {
         return(false);
     }
 }
Ejemplo n.º 7
0
 public bool AddDoctor(Doctor doc)
 {
     _dbService.Add(doc);
     try
     {
         _dbService.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
        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));
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public IActionResult AddDoctor(DoctorModel doctor)
        {
            try
            {
                if (doctor != null)
                {
                    _context.Add(doctor);
                    _context.SaveChanges();
                    return Ok("saved");
                }

                return NotFound();
            }
            catch { return BadRequest(); }

        }
Ejemplo n.º 11
0
        public Doctor CreateDoctor(Doctor doctor)
        {
            var newDoctor = _context.AddAsync(doctor);

            _context.SaveChanges();
            return(doctor);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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!");
            }
        }
Ejemplo n.º 15
0
        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));
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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));
        }
Ejemplo n.º 18
0
        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));
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 20
0
 private void Save()
 {
     _dbContext.SaveChanges();
 }
Ejemplo n.º 21
0
        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();
        }
Ejemplo n.º 22
0
        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());
        }
Ejemplo n.º 23
0
 public void AddDoctor(Doctor doctor)
 {
     _db.Add(doctor);
     _db.SaveChanges();
 }
Ejemplo n.º 24
0
 public void CreateDoctor(Doctor doctor)
 {
     _context.Doctor.Add(doctor);
     _context.SaveChanges();
 }