I want to save records in two model where one model can get single row and second model can get multiple row. Please help me to resolve it.
controller: PatientTestsController.cs
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> AddPatientTest(PatientTestsAndBilling ptb)
{
if (ModelState.IsValid)
{
}
return View(ptb);
}
Model : PatientTest
public class PatientTest
{
[Key]
public int Id { get; set; }
[Display(Name ="Patient Id")]
public int PatientId { get; set; }
[Display(Name ="Test Id")]
public int TestId { get; set; }
[Display(Name ="Doctor")]
public int DoctorId { get; set; }
[Display(Name="Center")]
public int CenterId { get; set; }
[Display(Name = "Test")]
[ForeignKey("TestId")]
//relation of Tests table
public virtual Tests Tests { get; set; }
[Display(Name = "Doctor Reference")]
[ForeignKey("DoctorId")]
//relation of Doctors table
public virtual Doctors Doctors { get; set; }
[Display(Name = "Center Reference")]
[ForeignKey("CenterId")]
//relation of Centers table
public virtual Centers Centers { get; set; }
[Display(Name = "Patient")]
[ForeignKey("PatientId")]
//relation of Patient table
public virtual Patient Patient { get; set; }
}
Model : PatientBilling
public class PatientTest
{
[Key]
public int Id { get; set; }
[Display(Name ="Patient Id")]
public int PatientId { get; set; }
[Display(Name ="Test Id")]
public int TestId { get; set; }
[Display(Name ="Doctor")]
public int DoctorId { get; set; }
[Display(Name="Center")]
public int CenterId { get; set; }
[Display(Name = "Test")]
[ForeignKey("TestId")]
//relation of Tests table
public virtual Tests Tests { get; set; }
[Display(Name = "Doctor Reference")]
[ForeignKey("DoctorId")]
//relation of Doctors table
public virtual Doctors Doctors { get; set; }
[Display(Name = "Center Reference")]
[ForeignKey("CenterId")]
//relation of Centers table
public virtual Centers Centers { get; set; }
[Display(Name = "Patient")]
[ForeignKey("PatientId")]
//relation of Patient table
public virtual Patient Patient { get; set; }
}
Model : PatientTestAndBilling
public class PatientTestsAndBilling
{
public List<PatientTest> patientTests { get; set; }
public PatientBilling patientBilling { get; set; }
}
this is my jquery code..
$("#save").click(function () {
var row = $('#table2 tbody tr').length;
var patientTest=[];
var patientBilling;
var j;
for (var i = 0; i < row; i++) {
j = i + 1;
patientTest.push({
PatientId: $('#patientId').val(),
TestId: $('#table2 tbody tr:nth-child('+j+')').attr('id'),
DoctorId: $('#doctor').val(),
CenterId: $('#center').val(),
});
}
patientBilling= {
PatientId: $('#patientId').val(),
TotalPrice: $('#total_price').text(),
PaidAmt: $('#total_paid').text(),
BalanceAmt: $('#balance').text(),
OtherCharges: $('#ot_charges').val(),
Discount: $('#discount').val(),
PaymentType: $('#payType').val()
};
var model = {
"patientTest": patientTest,
"patientBilling": patientBilling
}
alert(JSON.stringify(model));
$.ajax({
type: "POST",
url: "/Reception/PatientTests/AddPatientTest",
data: model,
headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
success: function (data) {
alert(data);
}
});
});
in this example I am getting only Patient Billing data not Patient test data please help me to resolve it..