public async Task <ActionResult> NameSearch(PhotoSearchModel model) { string usrid = "Guest"; if (User.Identity.IsAuthenticated) { usrid = User.Identity.GetUserId(); } List <Device> devices = await db.Devices.ToListAsync(); SelectList sl = new SelectList(devices, "DeviceID", "Name", "Empty"); model.DeviceList = sl; string searchName = ""; if (!string.IsNullOrWhiteSpace(model.Name)) { searchName = model.Name; } SqlParameter param1 = new SqlParameter("@UserID", usrid); SqlParameter param2 = new SqlParameter("@SString", searchName); var results = await db.Photos.SqlQuery("[dbo].[sp_SearchPhoto] @UserID,@SString", param1, param2).ToListAsync(); model.SearchResults = results; return(View("PhotoSearch", model)); }
public async Task <ActionResult> PhotoSearch() { string usrid = "Guest"; if (User.Identity.IsAuthenticated) { usrid = User.Identity.GetUserId(); } List <Device> devices = await db.Devices.ToListAsync(); Device dev = await db.Devices.FirstOrDefaultAsync(x => x.Name == "Empty"); int devID = 1; if (dev != null) { devID = dev.DeviceID; } SelectList sl = new SelectList(devices, "DeviceID", "Name", "Empty"); PhotoSearchModel model = new PhotoSearchModel(); model.DeviceList = sl; model.DeviceID = devID; return(View(model)); }
public async Task <ActionResult> AllSearch(PhotoSearchModel model) { DateTime?modelTimeFrom = null; if (!string.IsNullOrWhiteSpace(model.TimeFrom)) { DateTime timeFrom; if (DateTime.TryParseExact(model.TimeFrom, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out timeFrom)) { modelTimeFrom = timeFrom; } else { ModelState.AddModelError("", "Wrong TimeFrom."); } } DateTime?modelTimeTo = null; if (!string.IsNullOrWhiteSpace(model.TimeTo)) { DateTime timeTo; if (DateTime.TryParseExact(model.TimeTo, "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out timeTo)) { modelTimeTo = timeTo; } else { ModelState.AddModelError("", "Wrong TimeTo."); } } string usrid = "Guest"; if (User.Identity.IsAuthenticated) { usrid = User.Identity.GetUserId(); } List <Device> devices = await db.Devices.ToListAsync(); SelectList sl = new SelectList(devices, "DeviceID", "Name", "Empty"); model.DeviceList = sl; string searchName = ""; if (!string.IsNullOrWhiteSpace(model.Name)) { searchName = model.Name; } List <Photo> searchResults = new List <Photo>(); if (ModelState.IsValid) { searchResults = await(from p in db.Photos join ap in db.AlbumsToPhotos on p.PhotoID equals ap.PhotoID into pGroup from p_ap in pGroup.DefaultIfEmpty() where ((p.UserID == usrid) | (p_ap != null)) & (p.Name.Contains(searchName)) & ((p.TimeTaken >= modelTimeFrom) | (modelTimeFrom == null)) & ((p.TimeTaken <= modelTimeTo) | (modelTimeTo == null)) & ((p.Location.Contains(model.Location)) | (model.Location == null) | (model.Location == "")) & ((p.DeviceID == model.DeviceID) | (model.DeviceID == 1)) & ((p.Focus == model.Focus) | (model.Focus == null)) & ((p.Aperture == model.Aperture) | (model.Aperture == null) | (model.Aperture == "")) & ((p.Shutter == model.Shutter) | (model.Shutter == null) | (model.Shutter == "")) & ((p.ISO == model.ISO) | (model.ISO == null) | (model.ISO == "")) & ((p.Flash == model.Flash) | (model.Flash == null)) select p).Distinct().ToListAsync(); } model.SearchResults = searchResults; return(View("PhotoSearch", model)); }