public IActionResult ViewMummy(ViewBurialsBurialModel v)
        {
            // This is the burial we are looking at
            //Burial b = context.Burials.FromSqlRaw("SELECT * FROM Burial WHERE BurialSiteId = {0} AND BurialNumber = {1}", v.BurialSiteId, v.BurialNumber).ToList().First();
            Burial b = context.Burials.Where(o => o.BurialSiteId == v.BurialSiteId).Where(p => p.BurialNumber == v.BurialNumber).ToList().First();
            //BurialSite bs = context.BurialSites.FromSqlRaw("SELECT * FROM BurialSite WHERE BurialSiteId = {0}", v.BurialSiteId).ToList().First();
            BurialSite bs = context.BurialSites.Where(o => o.BurialSiteId == v.BurialSiteId).ToList().First();
            //List<CranialMain> cranialMains = context.CranialMains.FromSqlRaw("SELECT * FROM CranialMain WHERE BurialSiteId = {0} AND BurialNumber = {1}", v.BurialSiteId, v.BurialNumber).ToList();
            //List<C14datum> c14Data = context.C14data.FromSqlRaw("SELECT * FROM C14Data WHERE BurialSiteId = {0} AND \"Burial#\" = {1}", v.BurialSiteId, v.BurialNumber).ToList();
            //List<FieldBook> fieldBooks = context.FieldBooks.FromSqlRaw("SELECT * FROM FieldBooks WHERE BurialSiteID = {0} AND BurialNumber = {1}", v.BurialSiteId, v.BurialNumber).ToList();

            ViewBurialViewModel vbvm = new ViewBurialViewModel();

            vbvm.Burial     = b;
            vbvm.BurialSite = bs;
            //vbvm.C14Data = c14Data;
            //vbvm.CranialMains = cranialMains;
            //vbvm.FieldBooks = fieldBooks;
            // add image urls

            return(View(vbvm));
        }
        public IActionResult ViewBurials(int pageNum = 1)
        {
            ViewBurialsViewModel viewModel = new ViewBurialsViewModel();

            // Create a list of burials,
            // but not the normal ones, just with the info we want to see
            List <ViewBurialsBurialModel> vbbmList = new List <ViewBurialsBurialModel>();

            List <Burial> Burials = GlobalBurials
                                    .Skip((pageNum - 1) * pageSize)
                                    .Take(pageSize)
                                    .OrderBy(o => o.BurialSiteId)
                                    .ToList();

            // for each burial in our db
            foreach (Burial b in Burials)
            {
                // create a burials model
                ViewBurialsBurialModel vbbm = new ViewBurialsBurialModel();

                // grab it's burial number
                int    BurialNumber   = (int)b.BurialNumber;
                int    BurialSiteId   = (int)b.BurialSiteId;
                string OsteologyNotes = null;

                string Burialwesttohead  = null;
                string Burialwesttofeet  = null;
                string Burialsouthtohead = null;
                string Burialsouthtofeet = null;
                string Burialdepth       = null;
                string Length            = null;
                string Goods             = null;
                string GenderCode        = null;

                if (!(b.OsteologyNotes is null))
                {
                    OsteologyNotes = b.OsteologyNotes.ToString();
                }

                if (!(b.BurialWestToHead is null))
                {
                    Burialwesttohead = b.BurialWestToHead.ToString();
                }

                if (!(b.BurialWestToFeet is null))
                {
                    Burialwesttofeet = b.BurialWestToFeet.ToString();
                }

                if (!(b.BurialSouthToHead is null))
                {
                    Burialsouthtohead = b.BurialSouthToHead.ToString();
                }

                if (!(b.BurialSouthToFeet is null))
                {
                    Burialsouthtofeet = b.BurialSouthToFeet.ToString();
                }

                if (!(b.BurialDepth is null))
                {
                    Burialdepth = b.BurialDepth.ToString();
                }

                if (!(b.Length is null))
                {
                    Length = b.Length.ToString();
                }

                if (!(b.Goods is null))
                {
                    Goods = b.Goods.ToString();
                }

                if (!(b.GenderCode is null))
                {
                    GenderCode = b.GenderCode.ToString();
                }

                string NS       = "";
                string EW       = "";
                int    NSTop    = 0;
                int    NSBottom = 0;
                int    EWTop    = 0;
                int    EWBottom = 0;
                string Quadrant = "";


                BurialSite bs = context.BurialSites.Where(o => o.BurialSiteId == b.BurialSiteId).ToList().First();
                NS       = bs.Ns;
                EW       = bs.Ew;
                NSTop    = bs.Nstop ?? default(int);
                NSBottom = bs.Nsbottom ?? default(int);
                EWTop    = bs.Ewtop ?? default(int);
                EWBottom = bs.Ewbottom ?? default(int);
                Quadrant = bs.Quadrant;
                //var sql = "SELECT* FROM dbo.BurialSite WHERE BurialSiteId = {0}";

                ////context.BurialSites.FromSqlInterpolated($"SELECT * FROM dbo.BurialSite")
                //string NS = context
                //    .BurialSites
                //    .FromSqlRaw(sql, b.BurialSiteId).ToList().First().Ns.ToString();

                //int NSTop = (int)context
                //    .BurialSites
                //    .FromSqlRaw("SELECT * FROM BurialSite WHERE BurialSiteId = {0}", b.BurialSiteId).ToList().First().Nstop;

                //int NSBottom = NSTop + 10;

                //string EW = context
                //    .BurialSites
                //    .FromSqlRaw("SELECT * FROM BurialSite WHERE BurialSiteId = {0}", b.BurialSiteId).ToList().First().Ew.ToString();

                //int EWTop = (int)context
                //    .BurialSites
                //    .FromSqlRaw("SELECT * FROM BurialSite WHERE BurialSiteId = {0}", b.BurialSiteId).ToList().First().Ewtop;

                //int EWBottom = EWTop + 10;

                //string Quadrant = context
                //    .BurialSites
                //    .FromSqlRaw("SELECT * FROM BurialSite WHERE BurialSiteId = {0}", b.BurialSiteId).ToList().First().Quadrant.ToString();


                // add all the info to the vbbm
                vbbm.BurialNumber      = BurialNumber;
                vbbm.NS                = NS;
                vbbm.NSTop             = NSTop;
                vbbm.NSBottom          = NSBottom;
                vbbm.EW                = EW;
                vbbm.EWTop             = EWTop;
                vbbm.EWBottom          = EWBottom;
                vbbm.Quadrant          = Quadrant;
                vbbm.OsteologyNotes    = OsteologyNotes;
                vbbm.Burialwesttohead  = Burialwesttohead;
                vbbm.Burialwesttofeet  = Burialwesttofeet;
                vbbm.Burialsouthtohead = Burialsouthtohead;
                vbbm.Burialsouthtofeet = Burialsouthtofeet;
                vbbm.Burialdepth       = Burialdepth;
                vbbm.Length            = Length;
                vbbm.Goods             = Goods;
                vbbm.GenderCode        = GenderCode;
                vbbm.BurialSiteId      = BurialSiteId;

                vbbmList.Add(vbbm);
            }
            viewModel.Burials = vbbmList;

            //kinda like a constructor
            PageNumberingInfo pageNumber = new PageNumberingInfo
            {
                NumItemsPerPage = pageSize,
                CurrentPage     = pageNum,
                TotalNumItems   = (GlobalBurials.Count())
            };

            viewModel.PageNumberingInfo = pageNumber;

            viewModel.Filter = new ViewBurialsFilteringInfo();

            return(View(viewModel));
        }
        public IActionResult ViewBurials(ViewBurialsViewModel vbvm, int pageNum = 1)
        {
            Console.WriteLine("Starting!!!!!!!!!!!!!!!!!!!");
            ViewBurialsViewModel viewModel = new ViewBurialsViewModel();

            // Create a list of burials,
            // but not the normal ones, just with the info we want to see
            List <ViewBurialsBurialModel> vbbmList = new List <ViewBurialsBurialModel>();

            // filter the global burials
            List <Burial> newBurials = new List <Burial>();

            List <Burial> Burials = context.Burials.ToList();

            foreach (Burial bur in Burials)
            {
                Console.WriteLine("At burial: ");
                Console.WriteLine(bur.BurialNumber);                // get burial site info

                string NS       = "";
                string EW       = "";
                int    NSTop    = 0;
                int    NSBottom = 0;
                int    EWTop    = 0;
                int    EWBottom = 0;
                string Quadrant = "";

                BurialSite bs = context.BurialSites.Where(o => o.BurialSiteId == bur.BurialSiteId).ToList().First();
                NS       = bs.Ns;
                EW       = bs.Ew;
                NSTop    = bs.Nstop ?? default(int);
                NSBottom = bs.Nsbottom ?? default(int);
                EWTop    = bs.Ewtop ?? default(int);
                EWBottom = bs.Ewbottom ?? default(int);
                Quadrant = bs.Quadrant;

                //NS
                if (vbvm.Filter.NS == "N" && NS != "N")
                {
                    // continue means it skips this burial
                    continue;
                }
                if (vbvm.Filter.NS == "S" && NS != "S")
                {
                    continue;
                }

                //NSTop
                if (vbvm.Filter.NSTop != -42 && vbvm.Filter.NSTop != NSTop)
                {
                    continue;
                }

                //EW
                if (vbvm.Filter.EW == "E" && EW != "E")
                {
                    // continue means it skips this burial
                    continue;
                }
                if (vbvm.Filter.EW == "W" && EW != "W")
                {
                    continue;
                }

                //ewtop
                if (vbvm.Filter.EWTop != -42 && vbvm.Filter.EWTop != EWTop)
                {
                    continue;
                }

                //quadrant
                if (vbvm.Filter.Quadrant != "All" && vbvm.Filter.Quadrant != Quadrant)
                {
                    continue;
                }

                //west to head
                if (bur.BurialWestToHead != null)
                {
                    // we are allowed to cast to double
                    double wth = Convert.ToDouble(bur.BurialWestToHead);

                    if (wth < vbvm.Filter.BurialwesttoheadMin || wth > vbvm.Filter.BurialwesttoheadMax)
                    {
                        continue;
                    }
                }


                //west to feet
                if (bur.BurialWestToFeet != null)
                {
                    // we are allowed to cast to double
                    double wtf = Convert.ToDouble(bur.BurialWestToFeet);

                    if (wtf < vbvm.Filter.BurialwesttofeetMin || wtf > vbvm.Filter.BurialwesttofeetMax)
                    {
                        continue;
                    }
                }

                //south to head
                if (bur.BurialSouthToHead != null)
                {
                    // we are allowed to cast to double
                    double sth = Convert.ToDouble(bur.BurialSouthToHead);

                    if (sth < vbvm.Filter.BurialsouthtoheadMin || sth > vbvm.Filter.BurialsouthtoheadMax)
                    {
                        continue;
                    }
                }


                //south to feet
                if (bur.BurialSouthToFeet != null)
                {
                    // we are allowed to cast to double
                    double stf = Convert.ToDouble(bur.BurialSouthToFeet);

                    if (stf < vbvm.Filter.BurialsouthtofeetMin || stf > vbvm.Filter.BurialsouthtofeetMax)
                    {
                        continue;
                    }
                }


                //depth
                if (bur.BurialDepth != null)
                {
                    // we are allowed to cast to double
                    double d = Convert.ToDouble(bur.BurialDepth);

                    if (d < vbvm.Filter.BurialdepthMin || d > vbvm.Filter.BurialdepthMax)
                    {
                        continue;
                    }
                }


                // goods
                if (vbvm.Filter.Goods == "All")
                {
                    // include everything
                }
                else if (vbvm.Filter.Goods != bur.Goods)
                {
                    continue;
                }

                // gender codes
                if (vbvm.Filter.GenderCode == "All")
                {
                    // include everything
                }
                else if (vbvm.Filter.GenderCode != bur.GenderCode)
                {
                    continue;
                }

                // byu sampled
                if (vbvm.Filter.Byusample == "All")
                {
                    // include everything
                }
                else if (vbvm.Filter.Byusample != bur.ByuSample)
                {
                    continue;
                }


                // skullmagazine
                if (vbvm.Filter.SkullatMagazine == "All")
                {
                    // include everything
                }
                else if (vbvm.Filter.SkullatMagazine != bur.SkullAtMagazine)
                {
                    continue;
                }

                // skull age
                if (vbvm.Filter.AgeSkull2018 == "All")
                {
                    // include everything
                }
                else if (vbvm.Filter.AgeSkull2018 != bur.AgeSkull)
                {
                    continue;
                }

                // skull sex
                if (vbvm.Filter.SexSkull2018 == "All")
                {
                    // include everything
                }
                else if (vbvm.Filter.SexSkull2018 != bur.SexSkull)
                {
                    continue;
                }


                newBurials.Add(bur);
            }
            Console.WriteLine("Outingside of the filtering!!!!!!!!!!!!!!!!!!");

            GlobalBurials = newBurials;

            List <Burial> Burialss = GlobalBurials
                                     .Skip((pageNum - 1) * pageSize)
                                     .Take(pageSize)
                                     .OrderBy(o => o.BurialSiteId)
                                     .ToList();

            // for each burial in our db
            foreach (Burial b in Burialss)
            {
                Console.WriteLine("inside the newxt lop");
                // get burial site info

                string NS       = "";
                string EW       = "";
                int    NSTop    = 0;
                int    NSBottom = 0;
                int    EWTop    = 0;
                int    EWBottom = 0;
                string Quadrant = "";

                BurialSite bs = context.BurialSites.Where(o => o.BurialSiteId == b.BurialSiteId).ToList().First();
                NS       = bs.Ns;
                EW       = bs.Ew;
                NSTop    = bs.Nstop ?? default(int);
                NSBottom = bs.Nsbottom ?? default(int);
                EWTop    = bs.Ewtop ?? default(int);
                EWBottom = bs.Ewbottom ?? default(int);
                Quadrant = bs.Quadrant;

                // create a burials model
                ViewBurialsBurialModel vbbm = new ViewBurialsBurialModel();

                // grab it's burial number
                int    BurialNumber   = (int)b.BurialNumber;
                int    BurialSiteId   = (int)b.BurialSiteId;
                string OsteologyNotes = null;

                string Burialwesttohead  = null;
                string Burialwesttofeet  = null;
                string Burialsouthtohead = null;
                string Burialsouthtofeet = null;
                string Burialdepth       = null;
                string Length            = null;
                string Goods             = null;
                string GenderCode        = null;


                if (!(b.OsteologyNotes is null))
                {
                    OsteologyNotes = b.OsteologyNotes.ToString();
                }

                if (!(b.BurialWestToHead is null))
                {
                    Burialwesttohead = b.BurialWestToHead.ToString();
                }

                if (!(b.BurialWestToFeet is null))
                {
                    Burialwesttofeet = b.BurialWestToFeet.ToString();
                }

                if (!(b.BurialSouthToHead is null))
                {
                    Burialsouthtohead = b.BurialSouthToHead.ToString();
                }

                if (!(b.BurialSouthToFeet is null))
                {
                    Burialsouthtofeet = b.BurialSouthToFeet.ToString();
                }

                if (!(b.BurialDepth is null))
                {
                    Burialdepth = b.BurialDepth.ToString();
                }

                if (!(b.Length is null))
                {
                    Length = b.Length.ToString();
                }

                if (!(b.Goods is null))
                {
                    Goods = b.Goods.ToString();
                }

                if (!(b.GenderCode is null))
                {
                    GenderCode = b.GenderCode.ToString();
                }

                // add all the info to the vbbm
                vbbm.BurialNumber      = BurialNumber;
                vbbm.NS                = NS;
                vbbm.NSTop             = NSTop;
                vbbm.NSBottom          = NSBottom;
                vbbm.EW                = EW;
                vbbm.EWTop             = EWTop;
                vbbm.EWBottom          = EWBottom;
                vbbm.Quadrant          = Quadrant;
                vbbm.OsteologyNotes    = OsteologyNotes;
                vbbm.Burialwesttohead  = Burialwesttohead;
                vbbm.Burialwesttofeet  = Burialwesttofeet;
                vbbm.Burialsouthtohead = Burialsouthtohead;
                vbbm.Burialsouthtofeet = Burialsouthtofeet;
                vbbm.Burialdepth       = Burialdepth;
                vbbm.Length            = Length;
                vbbm.Goods             = Goods;
                vbbm.GenderCode        = GenderCode;
                vbbm.BurialSiteId      = BurialSiteId;

                vbbmList.Add(vbbm);
            }

            Console.WriteLine("outside the last loop!!!!!!!!!!!!!!");
            viewModel.Burials = vbbmList;

            //kinda like a constructor
            PageNumberingInfo pageNumber = new PageNumberingInfo
            {
                NumItemsPerPage = pageSize,
                CurrentPage     = pageNum,
                TotalNumItems   = (GlobalBurials.Count())
            };

            viewModel.PageNumberingInfo = pageNumber;

            viewModel.Filter = vbvm.Filter;

            return(View(viewModel));
        }