public List <ConsultationView> Last2Consultations(int?Patientid)
        {
            List <ConsultationView> cv = new List <ConsultationView>();

            var listss = consultrep.GetAll().FindAll(x => x.PatientId == Patientid).TakeLast(3).Reverse().ToList();

            foreach (var ite in listss)
            {
                ConsultationView cvob = new ConsultationView();
                cvob.ConsultDate = ite.ConsultDate;
                cvob.ConsultId   = ite.ConsultId;
                cvob.ConsultTime = ite.ConsultTime;
                cvob.Notes       = ite.Notes;
                //vob.illness = ite.illness;
                cvob.PatientId = ite.PatientId;
                cvob.Custs     = new List <ConsultationView.Cust>();
                cvob.Illnesses = new List <ConsultationView.Illness>();

                foreach (var item in ite.CustLis)
                {
                    ConsultationView.Cust obCust = new ConsultationView.Cust();
                    obCust.custId   = item.custId;
                    obCust.Dosage   = item.Dosage;
                    obCust.DrugId   = item.DrugId;
                    obCust.Quantity = item.Quantity;
                    cvob.Custs.Add(obCust);
                }
                foreach (var illness in ite.Illness)
                {
                    ConsultationView.Illness obillness = new ConsultationView.Illness();
                    obillness.Illnessid   = illness.Illnessid;
                    obillness.Illnessname = illness.Illnessname;
                    cvob.Illnesses.Add(obillness);
                }
                cv.Add(cvob);
            }
            return(cv);
        }
        public List <ConsultationView> GetAllConsultations()
        {
            using (var consultrepo = new ConsultationRepository())
            {
                List <ConsultationView>           consviewlist     = new List <ConsultationView>();
                List <ConsultationView.Cust>      conscustlist     = new List <ConsultationView.Cust>();
                ConsultationView.Illness          consillness      = new ConsultationView.Illness();
                List <ConsultationView.Illness>   consillnesslist  = new List <ConsultationView.Illness>();
                ConsultationView.procedure        conprocedure     = new ConsultationView.procedure();
                List <ConsultationView.procedure> conprocedurelist = new List <ConsultationView.procedure>();

                ConsultationView.TestType constexttype = new ConsultationView.TestType();
                var user = consultrepo.GetAll().ToList();

                foreach (var newitem in user)
                {
                    ConsultationView consview = new ConsultationView();
                    consview.symptomses = new List <SymptomsModel>();
                    consview.Illnesses  = new List <ConsultationView.Illness>();
                    consview.Custs      = new List <ConsultationView.Cust>();
                    consview.ConsultId  = newitem.ConsultId;
                    //illness = x.illness,
                    consview.PatientId   = newitem.PatientId;
                    consview.Symptoms    = newitem.Symptoms;
                    consview.Description = newitem.Description;
                    //PatientSname = x.PatientSname,
                    consview.ConsultDate = newitem.ConsultDate;
                    //PatientFname = x.PatientFname,
                    consview.PresribedMed    = newitem.PresribedMed;
                    consview.ConsultTime     = newitem.ConsultTime;
                    consview.TotalPrice      = newitem.TotalPrice;
                    consview.Notes           = newitem.Notes;
                    consview.patientfullname = newitem.patientfullname;
                    consview.resultFile      = pr.GetById(newitem.PatientId).File;
                    consview.FileName        = pr.GetById(newitem.PatientId).FileName;
                    consview.FileType        = pr.GetById(newitem.PatientId).FileType;
                    foreach (var cust in newitem.CustLis)
                    {
                        ConsultationView.Cust conscust = new ConsultationView.Cust();
                        var custtoadd = custrepo.Getall().Find(x => x.custId == cust.custId);
                        conscust.DrugId   = custtoadd.DrugId;
                        conscust.Dosage   = custtoadd.Dosage;
                        conscust.custId   = custtoadd.custId;
                        conscust.Quantity = custtoadd.Quantity;
                        consview.Custs.Add(conscust);
                    }
                    foreach (var symptom in newitem.Symptomses)
                    {
                        SymptomsModel Symptomsmodel = new SymptomsModel();
                        var           symotomstoadd = symptomrtepo.GetById(symptom.Symptomsid);
                        Symptomsmodel.symptomsname = symotomstoadd.symptomsname;
                        Symptomsmodel.Symptomsid   = symotomstoadd.Symptomsid;
                        consview.symptomses.Add(Symptomsmodel);
                    }
                    newitem.Illness = new List <Illness>();
                    foreach (var ill in newitem.Illness)
                    {
                        ConsultationView.Illness conill = new ConsultationView.Illness();
                        var symotomstoadd = illrepo.GetById(ill.Illnessid);
                        conill.Illnessname = symotomstoadd.Illnessname;
                        conill.Illnessid   = symotomstoadd.Illnessid;
                        consview.Illnesses.Add(conill);
                    }
                    consviewlist.Add(consview);
                }

                return(consviewlist);
            }
        }