/// <summary> /// Seeds the specified patient database context. /// </summary> /// <param name="patientDbContext">The patient database context.</param> public static void Seed(this PatientDbContext patientDbContext) { patientDbContext.Add(new Patient { Forename = $"Arindam", Surname = $"Dhar", DateOfBirth = Convert.ToDateTime("23/10/1985"), Gender = true, TelephoneNumber = "{\"WorkNumber\" : \"123456789\"}" }); patientDbContext.Add(new Patient { Forename = $"User1", Surname = $"Surname1", DateOfBirth = Convert.ToDateTime("03/01/1989"), Gender = true, TelephoneNumber = "{\"MobileNumber\" : \"123456789\", \"WorkNumber\" : \"234567\" }" }); patientDbContext.Add(new Patient { Forename = $"User2", Surname = $"Surname2", DateOfBirth = Convert.ToDateTime("03/01/1999"), Gender = false, TelephoneNumber = "{\"MobileNumber\" : \"123456789\", \"HomeNumber\" : \"9998645\"}" }); patientDbContext.SaveChanges(); }
public async Task <IActionResult> PostRecordAsync([FromBody] PatientModel request) { Logger?.LogDebug("'{0}' has been invoked", nameof(PostRecordAsync)); var response = new SingleResponse <PatientModel>(); try { var existingEntity = await DbContext .GetPatientDetailByNameAsync(new Patient { Forename = request.Forename, Surname = request.Surname }); if (existingEntity != null) { ModelState.AddModelError("PatientModel", "Patient name already exists"); } if (!ModelState.IsValid) { return(BadRequest()); } Patient entity = new Patient { Forename = request.Forename, Surname = request.Surname, Gender = request.Gender, DateOfBirth = request.DateOfBirth, TelephoneNumber = request.TelephoneNumber != null?JsonConvert.SerializeObject(request.TelephoneNumber) : null, CreatedOn = DateTime.UtcNow, CreatedBy = "System" }; // Add entity to repository DbContext.Add(entity); // Save entity in database await DbContext.SaveChangesAsync(); // Set the entity to response model response.Model = request; } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "There was an internal error, please contact to support."; Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(PostRecordAsync), ex); } return(response.ToHttpResponse()); }
public IActionResult AddDoctor(DoctorRequest doctorRequest) { if (_context.Doctor.Any(e => e.IdDoctor == doctorRequest.IdDoctor)) { return(BadRequest("Doctor already exists.")); } else { var doctor = new Doctor() { IdDoctor = doctorRequest.IdDoctor, Email = doctorRequest.Email, FirstName = doctorRequest.FirstName, LastName = doctorRequest.LastName, prescriptions = new List <Prescription>() }; _context.Add(doctor); _context.SaveChanges(); return(Ok("Doctor " + doctor.Email + " added!")); } }