public async Task <string> CreateNewAppointment(AppointmentDTO appointment) { using (var dbcxtransaction = _tandVardContext.Database.BeginTransaction()) { var tblInsertItem = new TblAppointment() { FldAppointmentBegin = appointment.FldAppointmentBegin, FldAppointmentEnd = appointment.FldAppointmentEnd, FldDenistIdFK = appointment.FldDenistIdFK, FldPatientFK = appointment.FldPatientFK }; if (!_tandVardContext.TblUsers.Any(x => x.FldUserId == tblInsertItem.FldDenistIdFK)) { throw new ArgumentException("The appointed dentist does not Exist"); } if (!_tandVardContext.TblPatients.Any(x => x.FldPatientId == tblInsertItem.FldPatientFK)) { throw new ArgumentException("The appointed patient does not Exist"); } var result = await _tandVardContext.TblAppointments.AddAsync(tblInsertItem); if (result.State.ToString() != "Added") { throw new Exception("Appointment was not added"); } _tandVardContext.SaveChanges(); dbcxtransaction.Commit(); return("Appointment was successfully created"); } }
public string AddPatients(PatientDTO patient) { using (var dbcxtransaction = _tandVardContext.Database.BeginTransaction()) { var tblInsertItem = new TblPatient() { FldFirstName = patient.FldFirstName, FldLastName = patient.FldLastName, FldAddress = patient.FldAddress, FldEmail = patient.FldEmail, FldSSnumber = patient.FldSSnumber, FldPhoneNumber = patient.FldPhoneNumber }; var result = _tandVardContext.TblPatients.Add(tblInsertItem); if (result.State.ToString() == "Added") { _tandVardContext.SaveChanges(); dbcxtransaction.Commit(); return("New patient created"); } else { throw new Exception("Something went wrong"); } } }