public IActionResult BurialDetails(int burialid) { //gets all the details for a specifc burial from the database var mummy = new MummyInfo(); mummy.burial = context.Burial.Where(x => x.BurialId == burialid).FirstOrDefault(); mummy.body = context.Body.Where(x => x.BodyId == mummy.burial.BodyId).FirstOrDefault(); mummy.bone = context.Bone.Where(x => x.BoneId == mummy.body.BoneId).FirstOrDefault(); mummy.cranial = context.Cranial.Where(x => x.CranialId == mummy.body.CranialId).FirstOrDefault(); mummy.excavation = context.Excavation.Where(x => x.ExcavationId == mummy.burial.ExcavationId).FirstOrDefault(); foreach (var f in context.Files) { if (f.BurialId == mummy.burial.BurialId) { mummy.files.Add(f); } } mummy.location = context.Location.Where(x => x.LocId == mummy.burial.LocId).FirstOrDefault(); mummy.physicalOrientation = context.PhysicalOrientation.Where(x => x.OrientationId == mummy.burial.OrientationId).FirstOrDefault(); foreach (Sample s in context.Sample) { if (s.BodyId == mummy.body.BodyId) { mummy.sample.Add(s); } } foreach (var s in context.Storage) { foreach (var sam in mummy.sample) { if (s.SampleId == sam.SampleId) { mummy.storage.Add(s); } } } foreach (var t in context.Tooth) { if (t.BodyId == mummy.body.BodyId) { mummy.tooth.Add(t); } } return(View(mummy)); }
public IActionResult BurialList(string depth, string age, string haircolor, string headdirection, string artifacts, string gender, int pagenum = 1) { ItemsPerPage = 4; var mummies = new MummyAndPage(); mummies.FilterCriteria.age = age; mummies.FilterCriteria.haircolor = haircolor; mummies.FilterCriteria.headdirection = headdirection; mummies.FilterCriteria.artifacts = artifacts; mummies.FilterCriteria.gender = gender; var burialList = new List <Burial>(); //checks if any filtering criteria have been specified, if not, it gets the first five, if yes it gets all to start) if (depth == null && age == null && haircolor == null && headdirection == null && artifacts == null && gender == null) { mummies.PageInfo = new PageNumberingInfo { PageSize = ItemsPerPage, //gets number of total mummies TotalMummies = context.Burial.Count(), CurrentPage = pagenum }; burialList = context.Burial .Skip((pagenum - 1) * ItemsPerPage) .Take(ItemsPerPage) .ToList(); } else { burialList = context.Burial.ToList(); } //gets all the information from the database and ties it together foreach (var b in burialList) { var mummy = new MummyInfo(); mummy.burial = b; mummy.body = context.Body.FirstOrDefault(x => x.BodyId == b.BodyId); if (mummy.body != null) { mummy.bone = context.Bone.FirstOrDefault(x => x.BoneId == mummy.body.BoneId); mummy.cranial = context.Cranial.FirstOrDefault(x => x.CranialId == mummy.body.CranialId); foreach (Sample s in context.Sample) { if (s.BodyId == mummy.body.BodyId) { mummy.sample.Add(s); } } foreach (var t in context.Tooth) { if (t.BodyId == mummy.body.BodyId) { mummy.tooth.Add(t); } } } mummy.excavation = context.Excavation.FirstOrDefault(x => x.ExcavationId == b.ExcavationId); foreach (var f in context.Files) { if (f.BurialId == b.BurialId) { mummy.files.Add(f); } } mummy.location = context.Location.FirstOrDefault(x => x.LocId == b.LocId); mummy.physicalOrientation = context.PhysicalOrientation.FirstOrDefault(x => x.OrientationId == b.OrientationId); foreach (var s in context.Storage) { foreach (var sam in mummy.sample) { if (s.SampleId == sam.SampleId) { mummy.storage.Add(s); } } } mummies.Mummies.Add(mummy); } //Code to remove items that don't meet the specified criteria //if (depth != null) //{ // if (depth == "small") // { // mummies.Mummies.OrderBy(x => x.physicalOrientation.BurialDepth); // } // else if (depth == "big") // { // mummies.Mummies.OrderByDescending(x => x.physicalOrientation.BurialDepth); // } //} if (age != null) { foreach (var m in mummies.Mummies.ToList()) { if (m.body != null) { if (m.body.AgeKey != age || m.body.AgeKey == null) { mummies.Mummies.Remove(m); } } else { mummies.Mummies.Remove(m); } } } if (haircolor != null) { foreach (var m in mummies.Mummies.ToList()) { if (m.body != null) { if (m.body.HairColorKey != haircolor || m.body.HairColorKey == null) { mummies.Mummies.Remove(m); } } else { mummies.Mummies.Remove(m); } } } if (headdirection != null) { foreach (var m in mummies.Mummies.ToList()) { if (m.physicalOrientation != null) { if (m.physicalOrientation.HeadDirection != headdirection || m.physicalOrientation.HeadDirection == null) { mummies.Mummies.Remove(m); } } else { mummies.Mummies.Remove(m); } } } if (artifacts != null) { foreach (var m in mummies.Mummies.ToList()) { if (m.burial != null) { bool artifactsBool = bool.Parse(artifacts); if (m.burial.ArtifactFound == null || m.burial.ArtifactFound != artifactsBool) { mummies.Mummies.Remove(m); } } else { mummies.Mummies.Remove(m); } } } if (gender != null) { foreach (var m in mummies.Mummies.ToList()) { if (m.body != null) { if (m.body.GenderKey != gender || m.body.GenderKey == null) { mummies.Mummies.Remove(m); } } else { mummies.Mummies.Remove(m); } } } //if we filtered, it resets the pagination so that it shows correctly if (depth != null || age != null || haircolor != null || headdirection != null || artifacts != null || gender != null) { mummies.PageInfo = new PageNumberingInfo { PageSize = ItemsPerPage, //gets number of total mummies TotalMummies = mummies.Mummies.Count, CurrentPage = pagenum }; mummies.Mummies = mummies.Mummies.Skip((pagenum - 1) * ItemsPerPage) .Take(ItemsPerPage) .ToList(); } //returns the few along with the list of mummies and the pagination information return(View("BurialList", mummies)); }