public TreatmentRecords Update(TreatmentRecords treatmentRecordsChanges)
        {
            var treatmentRecords = Context.TreatmentRecords.Attach(treatmentRecordsChanges);

            treatmentRecords.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            Context.SaveChanges();
            return(treatmentRecordsChanges);
        }
        public TreatmentRecords Delete(int id)
        {
            TreatmentRecords tr = Context.TreatmentRecords.Include(a => a.Patient).ThenInclude(a => a.Address).Include(a => a.Hospital).ThenInclude(a => a.Address).Include(a => a.Disease)
                                  .Include(a => a.Patient).ThenInclude(a => a.Occupation)
                                  .Include(a => a.Patient).ThenInclude(a => a.Organisation).ThenInclude(a => a.Address).FirstOrDefault(x => x.TreatmentRecordsId == id);

            if (tr != null)
            {
                Context.TreatmentRecords.Remove(tr);
                Context.SaveChanges();
            }
            return(tr);
        }
        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);
        }
 public void Put(int TreatmentRecordsId, [FromBody] TreatmentRecords treatmentRecords) => treatmentRecordsRepository.Update(treatmentRecords);