public TreatmentRecordsDto Update(int id, TreatmentRecordsDto treatmentRecordsDto)
        {
            var treatmentRecords = Context.TreatmentRecords.FirstOrDefault(e => e.TreatmentRecordsId == id);
            {
                treatmentRecords.IsFatal       = treatmentRecordsDto.IsFatal;
                treatmentRecords.Currentstage  = treatmentRecordsDto.Currentstage;
                treatmentRecords.AdmittedDate  = treatmentRecordsDto.AdmittedDate;
                treatmentRecords.RelievingDate = treatmentRecordsDto.RelievingDate;
                treatmentRecords.Prescription  = treatmentRecordsDto.Prescription;
            }
            var patient = Context.Patients.FirstOrDefault(x => x.PatientID == treatmentRecords.PatientID);
            {
                patient.PatientName = treatmentRecordsDto.PatientName;
                patient.PAge        = treatmentRecordsDto.PAge;
                patient.PGender     = treatmentRecordsDto.PGender;
                patient.PEmail      = treatmentRecordsDto.PEmail;
                patient.AadharID    = treatmentRecordsDto.AadharID;
                patient.PContact    = treatmentRecordsDto.PContact;
            }

            var address = Context.Addresses.FirstOrDefault(x => x.AddressId == treatmentRecords.Patient.AddressId);
            {
                address.AddressType = treatmentRecordsDto.AddressType;
                address.StreetNo    = treatmentRecordsDto.StreetNo;
                address.Area        = treatmentRecordsDto.Area;
                address.City        = treatmentRecordsDto.City;
                address.State       = treatmentRecordsDto.State;
                address.Country     = treatmentRecordsDto.Country;
                address.ZipCode     = treatmentRecordsDto.ZipCode;
            }

            var hospital = Context.Hospitals.FirstOrDefault(x => x.HospitalId == treatmentRecords.HospitalId);
            {
                hospital.HospitalName = treatmentRecordsDto.HospitalName;
                hospital.Contact      = treatmentRecordsDto.Contact;
            }


            var hosaddress = Context.Addresses.FirstOrDefault(x => x.AddressId == treatmentRecords.Hospital.AddressId);
            {
                hosaddress.AddressType = treatmentRecordsDto.Hos_AddressType;
                hosaddress.StreetNo    = treatmentRecordsDto.Hos_StreetNo;
                hosaddress.Area        = treatmentRecordsDto.Hos_Area;
                hosaddress.City        = treatmentRecordsDto.Hos_City;
                hosaddress.State       = treatmentRecordsDto.Hos_State;
                hosaddress.Country     = treatmentRecordsDto.Hos_Country;
                hosaddress.ZipCode     = treatmentRecordsDto.Hos_ZipCode;
            }

            var disease = Context.Diseases.FirstOrDefault(x => x.DiseaseId == treatmentRecords.DiseaseId);

            {
                disease.DiseaseName = treatmentRecordsDto.DiseaseName;
                disease.DiseaseType = treatmentRecordsDto.DiseaseType;
            }

            Context.SaveChanges();
            return(treatmentRecordsDto);
        }
 //public void AddTreatmentRecords([FromBody] TreatmentRecords treatmentRecords) => treatmentRecordsRepository.Add(treatmentRecords);
 public ActionResult <TreatmentRecordsDto> PostTreatmentRecords(TreatmentRecordsDto treatmentRecordsDto)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Invalid Data"));
     }
     treatmentRecordsRepository.AddTreatmentRecords(treatmentRecordsDto);
     return(Ok("Added Successfully."));
 }
 public ActionResult Put(int id, TreatmentRecordsDto treatmentRecordsDto)
 {
     if (id > 0)
     {
         treatmentRecordsRepository.Update(id, treatmentRecordsDto);
         return(Ok("Patient Details Updated"));
     }
     return(NotFound("Patient with Id " + id.ToString() + " not found to update"));
 }
        public TreatmentRecordsDto AddTreatmentRecords(TreatmentRecordsDto treatmentRecordsDto)
        {
            Address addr = new Address()
            {
                AddressId   = treatmentRecordsDto.AddressId,
                AddressType = treatmentRecordsDto.AddressType,
                StreetNo    = treatmentRecordsDto.StreetNo,
                Area        = treatmentRecordsDto.Area,
                City        = treatmentRecordsDto.City,
                State       = treatmentRecordsDto.State,
                Country     = treatmentRecordsDto.Country,
                ZipCode     = treatmentRecordsDto.ZipCode,
            };

            Context.Addresses.Add(addr);
            Context.SaveChanges();
            int addressid = addr.AddressId;

            Patient pat = new Patient()
            {
                PatientID   = treatmentRecordsDto.PatientID,
                PatientName = treatmentRecordsDto.PatientName,
                PAge        = treatmentRecordsDto.PAge,
                PGender     = treatmentRecordsDto.PGender,
                PEmail      = treatmentRecordsDto.PEmail,
                AadharID    = treatmentRecordsDto.AadharID,
                PContact    = treatmentRecordsDto.PContact,
                AddressId   = addressid,
            };

            Context.Patients.Add(pat);
            Context.SaveChanges();
            int patientid = pat.PatientID;

            Occupation occ = new Occupation()
            {
                OccupationId   = treatmentRecordsDto.OccupationId,
                OccupationName = treatmentRecordsDto.OccupationName,
                OccupationType = treatmentRecordsDto.OccupationType,
                PatientID      = patientid,
            };

            Context.Occupations.Add(occ);
            Context.SaveChanges();
            int occupationid = occ.OccupationId;

            Address orgaddr = new Address()
            {
                AddressId   = treatmentRecordsDto.Org_AddressId,
                AddressType = treatmentRecordsDto.Org_AddressType,
                StreetNo    = treatmentRecordsDto.Org_StreetNo,
                Area        = treatmentRecordsDto.Org_Area,
                City        = treatmentRecordsDto.Org_City,
                State       = treatmentRecordsDto.Org_State,
                Country     = treatmentRecordsDto.Org_Country,
                ZipCode     = treatmentRecordsDto.Org_ZipCode,
            };

            Context.Addresses.Add(orgaddr);
            Context.SaveChanges();
            int orgaddressid = orgaddr.AddressId;

            Organisation org = new Organisation()
            {
                OrganisationId      = treatmentRecordsDto.OrganisationId,
                OrganisationName    = treatmentRecordsDto.OrganisationName,
                OrganisationContact = treatmentRecordsDto.OrganisationContact,
                PatientID           = patientid,
                AddressId           = orgaddressid,
            };

            Context.Organisations.Add(org);
            Context.SaveChanges();

            Address hosaddr = new Address()
            {
                AddressId   = treatmentRecordsDto.Hos_AddressId,
                AddressType = treatmentRecordsDto.Hos_AddressType,
                StreetNo    = treatmentRecordsDto.Hos_StreetNo,
                Area        = treatmentRecordsDto.Hos_Area,
                City        = treatmentRecordsDto.Hos_City,
                State       = treatmentRecordsDto.Hos_State,
                Country     = treatmentRecordsDto.Hos_Country,
                ZipCode     = treatmentRecordsDto.Hos_ZipCode,
            };

            Context.Addresses.Add(hosaddr);
            Context.SaveChanges();
            int hosaddressid = hosaddr.AddressId;

            Hospital hos = new Hospital()
            {
                HospitalId   = treatmentRecordsDto.HospitalId,
                HospitalName = treatmentRecordsDto.HospitalName,
                Contact      = treatmentRecordsDto.Contact,
                AddressId    = hosaddressid,
            };

            Context.Hospitals.Add(hos);
            Context.SaveChanges();
            int hospitalid = hos.HospitalId;

            Disease dis = new Disease()
            {
                DiseaseId   = treatmentRecordsDto.DiseaseId,
                DiseaseName = treatmentRecordsDto.DiseaseName,
                DiseaseType = treatmentRecordsDto.DiseaseType
            };

            Context.Diseases.Add(dis);
            Context.SaveChanges();
            int diseaseid = dis.DiseaseId;



            TreatmentRecords trtr = new TreatmentRecords()
            {
                TreatmentRecordsId = treatmentRecordsDto.TreatmentRecordsId,
                PatientID          = patientid,
                HospitalId         = hospitalid,
                DiseaseId          = diseaseid,
                AdmittedDate       = treatmentRecordsDto.AdmittedDate,
                Prescription       = treatmentRecordsDto.Prescription,
                RelievingDate      = treatmentRecordsDto.RelievingDate,
                IsFatal            = treatmentRecordsDto.IsFatal,
                Currentstage       = treatmentRecordsDto.Currentstage
            };

            Context.TreatmentRecords.Add(trtr);
            Context.SaveChanges();
            int treatmentrecordsid = trtr.TreatmentRecordsId;

            return(treatmentRecordsDto);
        }