public IActionResult UploadPhoto(string id) { string newid = id.Replace("%2F", "/"); if (newid == null) { return(NotFound()); } BurialListViewModel blvm = new BurialListViewModel { burial = _context.Burials.Where(x => x.BurialId == newid).FirstOrDefault() }; return(View(blvm)); }
public async Task <IActionResult> SavePhoto(BurialListViewModel photo) { // magic happens here // check if model is not empty //Photo uploadPhoto = (Photo)photo.ImageUpload; var x = photo.ImageUpload; string id = x.BurialId; string fileName = x.file.FileName; if (ModelState.IsValid) { // create new entity await _s3Storage.AddItem(photo.ImageUpload.file, "ForFun"); Photo PhotoTable = new Photo { BurialId = x.BurialId, PhotoId = fileName, Burial = _context.Burials.Where(x => x.BurialId == id).FirstOrDefault() }; Burial bur = _context.Burials.Where(x => x.BurialId == id).FirstOrDefault(); _context.Photos.Add(PhotoTable); await _context.SaveChangesAsync(); return(View("Details", new PhotosViewModel() { Photos = _context.Photos .Where(x => x.BurialId == id), Burial = _context.Burials .Where(x => x.BurialId == id).FirstOrDefault() })); } else { return(View("Home")); } }
// GET: Burial public async Task <IActionResult> Index(string id, int page = 1) { var filters = new Filters(id); ViewBag.Filters = filters; // Drop down options for filters List <string> squareIds = new List <string>(); foreach (Square s in _context.Squares.Distinct().ToList()) { string squareId = s.LowPairNs.ToString() + '/' + s.HighPairNs.ToString() + ' ' + s.BurialLocationNs.ToString() + ' ' + s.LowPairEw.ToString() + '/' + s.HighPairEw.ToString() + ' ' + s.BurialLocationEw.ToString(); squareIds.Add(squareId); } ViewBag.Square = _context.Squares.Distinct().ToList(); ViewBag.Area = new List <string> { "NE", "NW", "SW", "SE" }; ViewBag.PhotoTaken = new List <string> { "true", "false" }; ViewBag.BurialGoods = new List <string> { "true", "false" }; ViewBag.Sex = new List <string> { "U", "F", "M", "S" }; ViewBag.HairColor = new List <string> { "Blonde", "Red Brown", "Light Brown", "Brown", "Red", "Black", "Dark Brown" }; ViewBag.FaceBundle = new List <string> { "U", "Y" }; ViewBag.HeadDirection = new List <string> { "E", "I", "U", "W" }; ViewBag.EstimatedAge = _context.Burials.Select(p => p.EstimatedAge).Distinct().ToList(); BurialListViewModel burialListViewModel = new BurialListViewModel { Areas = _context.Areas, Squares = _context.Squares, Burials = _context.Burials, Filters = filters, PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalNumItems = 0 } }; // Filter context based on filters if (filters.HasSquare) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.SquareId == Convert.ToDecimal(filters.Square)); } if (filters.HasArea) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.AreaId == burialListViewModel.Areas.Where(x => x.Area1 == filters.Area).FirstOrDefault().AreaId); } if (filters.HasMinLength) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.Length >= Convert.ToDecimal(filters.MinLength)); } if (filters.HasMaxLength) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.Length <= Convert.ToDecimal(filters.MaxLength)); } if (filters.HasMinDepth) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.Depth >= Convert.ToDecimal(filters.MinDepth)); } if (filters.HasMaxDepth) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.Depth <= Convert.ToDecimal(filters.MaxDepth)); } if (filters.HasPhotoTaken) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.PhotoTaken == Convert.ToBoolean(filters.PhotoTaken)); } if (filters.HasBurialGoods) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.BurialGoods == Convert.ToBoolean(filters.BurialGoods)); } if (filters.HasSex) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.SexBody == filters.Sex); } if (filters.HasHairColor) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.HairColor == filters.HairColor); } if (filters.HasFaceBundle) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.FaceBundle == filters.FaceBundle); } if (filters.HasHeadDirection) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.HeadDirection == filters.HeadDirection); } if (filters.HasEstimatedAge) { burialListViewModel.Burials = burialListViewModel.Burials.Where(t => t.EstimatedAge == filters.EstimatedAge); } // Find total num items and return number PageSize burialListViewModel.PagingInfo.TotalNumItems = burialListViewModel.Burials.Count(); burialListViewModel.Burials = burialListViewModel.Burials.Skip((page - 1) * PageSize).Take(PageSize); return(View("Index", burialListViewModel)); }
public IActionResult PagedIndex(BurialListViewModel blvm, int pagenum = 1) { return(View("Index", blvm)); }
public IActionResult AdvancedFiltering(BurialListViewModel filterAtr) { //default values for search string sex = "%"; string area = "%"; double length = 0.00; double depth = 0.00; string bdirection = "%"; string nors = "%"; string eorw = "%"; string burialid = "%"; string haircolor = "%"; //set variables if user used filters if (filterAtr.FilterItems != null) { sex = filterAtr.FilterItems.Sex; area = filterAtr.FilterItems.Area; length = filterAtr.FilterItems.Length; depth = filterAtr.FilterItems.Depth; bdirection = filterAtr.FilterItems.BDirection; nors = filterAtr.FilterItems.NorS; eorw = filterAtr.FilterItems.EorW; burialid = filterAtr.FilterItems.BurialId; haircolor = filterAtr.FilterItems.HairColorCode; } //set % for ALL so it returns all values that arent null if (sex == "ALL") { sex = "%"; } if (area == "ALL") { area = "%"; } if (bdirection == "ALL") { bdirection = "%"; } if (nors == "ALL") { nors = "%"; } if (eorw == "ALL") { eorw = "%"; } if (haircolor == "ALL") { haircolor = "%"; } burialid = "%" + burialid + "%"; return(View(new BurialListViewModel { //filter based off users selections //users selection is passed through variable to prevent SQL injections Burials = _context.Burials .FromSqlInterpolated($"SELECT * FROM Burials WHERE Gender_Code LIKE {sex} AND Square LIKE {area} AND Burial_Direction LIKE {bdirection} AND North_or_South LIKE {nors} AND East_or_West LIKE {eorw} AND BurialID LIKE {burialid} AND Hair_Color_Code LIKE {haircolor}") .Where(b => b.LengthM >= length) .Where(b => b.BurialDepth >= depth) .OrderBy(b => b.BurialId) .ToList(), })); }
// GET method for Burial List view public IActionResult BurialList(long?burialId, string gender, string hairColor, int?yearExc, string monthExc, string headDir, string fieldBook, string byuSamp, string skullMag, string sexSkull, string ageSkull, decimal?wtHead, decimal?wtFeet, string burialPres, string burialWrap, string gendMeth, string ageCode, string faceBundle, decimal?burDepth, decimal?stHead, decimal?stFeet, int?Length, string genGe, string searchBox, int pageNum = 1) { // Sets the page size to 47 int pageSize = 47; var BurialListView = new BurialListViewModel { Burials = _context.Burials .Where(x => x.BurialId == burialId || burialId == null) .Where(x => x.Gender == gender || gender == null) .Where(x => x.HairColor == hairColor || hairColor == null) .Where(x => x.YearExc == yearExc || yearExc == null) .Where(x => x.MonthExc == monthExc || monthExc == null) .Where(x => x.HeadDirection == headDir || headDir == null) .Where(x => x.FieldBook == fieldBook || fieldBook == null) .Where(x => x.ByuSample == byuSamp || byuSamp == null) .Where(x => x.SkullMag == skullMag || skullMag == null) .Where(x => x.SexSkull == sexSkull || sexSkull == null) .Where(x => x.AgeSkull == ageSkull || ageSkull == null) .Where(x => x.WestToHead == wtHead || wtHead == null) .Where(x => x.WestToFeet == wtFeet || wtFeet == null) .Where(x => x.BurialPreservation == burialPres || burialPres == null) .Where(x => x.BurialWrapping == burialWrap || burialWrap == null) .Where(x => x.BurialGendMeth == gendMeth || gendMeth == null) .Where(x => x.AgeCode == ageCode || ageCode == null) .Where(x => x.FaceBundle == faceBundle || faceBundle == null) .Where(x => x.BurialDepth == burDepth || burDepth == null) .Where(x => x.SouthToHead == stHead || stHead == null) .Where(x => x.SouthToFeet == stFeet || stFeet == null) .Where(x => x.Length == Length || Length == null) .Where(x => x.GenderGe == genGe || genGe == null) .Where(x => x.Notes.Contains(searchBox) || x.OsteologyNotes.Contains(searchBox) || x.BurialSituation.Contains(searchBox) || searchBox == null) .OrderByDescending(x => x.BurialId) .Skip((pageNum - 1) * pageSize) .Take(pageSize) .ToList(), BioSamples = _context.BioSamples .Where(x => x.LocationId == _context.Burials.Select(x => x.LocationId).ToString()) .Where(x => x.Notes.Contains(searchBox) || searchBox == null), Cranials = _context.Cranials .Where(x => x.LocationId == _context.Burials.Select(x => x.LocationId).ToString()) .Where(x => x.BurialArtDescription.Contains(searchBox) || searchBox == null), CarbonDatings = _context.CarbonDatings .Where(x => x.LocationId == _context.Burials.Select(x => x.LocationId).ToString()) .Where(x => x.Notes.Contains(searchBox) || searchBox == null), PageNumbering = new PageNumbering { NumItemsPerPage = pageSize, CurrentPage = pageNum, TotalItems = _context.Burials .Where(x => x.BurialId == burialId || burialId == null) .Where(x => x.Gender == gender || gender == null) .Where(x => x.HairColor == hairColor || hairColor == null) .Where(x => x.YearExc == yearExc || yearExc == null) .Where(x => x.MonthExc == monthExc || monthExc == null) .Where(x => x.HeadDirection == headDir || headDir == null) .Where(x => x.FieldBook == fieldBook || fieldBook == null) .Where(x => x.ByuSample == byuSamp || byuSamp == null) .Where(x => x.SkullMag == skullMag || skullMag == null) .Where(x => x.SexSkull == sexSkull || sexSkull == null) .Where(x => x.AgeSkull == ageSkull || ageSkull == null) .Where(x => x.WestToHead == wtHead || wtHead == null) .Where(x => x.WestToFeet == wtFeet || wtFeet == null) .Where(x => x.BurialPreservation == burialPres || burialPres == null) .Where(x => x.BurialWrapping == burialWrap || burialWrap == null) .Where(x => x.BurialGendMeth == gendMeth || gendMeth == null) .Where(x => x.AgeCode == ageCode || ageCode == null) .Where(x => x.FaceBundle == faceBundle || faceBundle == null) .Where(x => x.BurialDepth == burDepth || burDepth == null) .Where(x => x.SouthToHead == stHead || stHead == null) .Where(x => x.SouthToFeet == stFeet || stFeet == null) .Where(x => x.Length == Length || Length == null) .Where(x => x.GenderGe == genGe || genGe == null) .Where(x => x.Notes.Contains(searchBox) || x.OsteologyNotes.Contains(searchBox) || x.BurialSituation.Contains(searchBox) || searchBox == null).Count() }, Filters = new FilterViewModel { gender = gender, hairColor = hairColor, yearExc = yearExc, monthExc = monthExc, headDir = headDir, fieldBook = fieldBook, byuSamp = byuSamp, skullMag = skullMag, sexSkull = sexSkull, ageSkull = ageSkull, wtHead = wtHead, wtFeet = wtFeet, burialPres = burialPres, burialWrap = burialWrap, gendMeth = gendMeth, ageCode = ageCode, faceBundle = faceBundle, burDepth = burDepth, stHead = stHead, stFeet = stFeet, Length = Length, genGe = genGe }, BurialId = (int?)burialId }; return(View(BurialListView)); }