Exemplo n.º 1
0
        public async Task <DatabaseModels.Patient> AddPatient(PatientRequest patientRequest)
        {
            var request = new DatabaseModels.Patient
            {
                Id          = new Guid(),
                CreatedAt   = DateTime.Now,
                UpdatedAt   = DateTime.Now,
                Email       = patientRequest.Email,
                DateOfBirth = patientRequest.DateOfBirth,
                FirstName   = patientRequest.FirstName,
                Gender      = patientRequest.Gender,
                IsActive    = patientRequest.IsActive,
                LastName    = patientRequest.LastName,
                Phone       = patientRequest.Phone
            };

            _apiContext.Patients.Add(request);

            var response = await _apiContext.SaveChangesAsync();

            return(request);
        }
Exemplo n.º 2
0
        public async Task <DatabaseModels.Patient> UpdatePatient(PatientRequest patientRequest, Guid id)
        {
            var request = new DatabaseModels.Patient
            {
                Id          = id,
                UpdatedAt   = DateTime.Now,
                Email       = patientRequest.Email,
                DateOfBirth = patientRequest.DateOfBirth,
                FirstName   = patientRequest.FirstName,
                Gender      = patientRequest.Gender,
                IsActive    = patientRequest.IsActive,
                LastName    = patientRequest.LastName,
                Phone       = patientRequest.Phone
            };
            var entry = _apiContext.Patients.First(e => e.Id == request.Id);

            _apiContext.Entry(entry).CurrentValues.SetValues(request);

            var response = await _apiContext.SaveChangesAsync();

            return(request);
        }
        private void AddTestData(ApiContext context)
        {
            for (int i = 1; i <= 15; i++)
            {
                Database.Models.Patient p = new Database.Models.Patient
                {
                    DateOfBirth = "12/12/2012",
                    FirstName   = $"Sam {i}",
                    LastName    = $"Smith {i}",
                    Email       = $"Test{i}@test.com.au",
                    Gender      = "Male",
                    Id          = new Guid(),
                    IsActive    = true,
                    Phone       = $"123123{i}",
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                context.Add(p);
            }


            context.SaveChanges();
        }