public HttpResponseMessage SearchGetPhotos(string userId, string collectionId, string cameraSites, string publicUserCollections, string hours, string months, string sites, string tags, string dates, string group) { SearchModel model = new SearchModel(); model.UserId = userId; model.CollectionId = collectionId; model.CameraSites = Convert.ToBoolean(cameraSites); model.PublicUserCollections = Convert.ToBoolean(publicUserCollections); model.Sites = sites; model.Tags = tags; model.Dates = dates; model.Hours = hours; model.Months = months; model.Group = group; List<long> ids = SearchService.SearchResultPhotoIds(model); HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.OK); message.Content = new StringContent(string.Join(",", ids)); return message; }
private String GetSearchQuery(SearchModel model) { StringBuilder select = new StringBuilder(); StringBuilder parameters = new StringBuilder(); StringBuilder publicPhotosBuilder = new StringBuilder(); StringBuilder collectionBuilder = new StringBuilder(); StringBuilder sitesBuilder = new StringBuilder(); StringBuilder tagBuilder = new StringBuilder(); StringBuilder monthBuilder = new StringBuilder(); StringBuilder dateBuilder = new StringBuilder(); StringBuilder hourBuilder = new StringBuilder(); publicPhotosBuilder = PublicPhotosQuery(model.UserId, model.CameraSites, model.PublicUserCollections); if (!String.IsNullOrWhiteSpace(model.CollectionId)) { collectionBuilder = CollectionQuery(model.CollectionId); } //Sites if (!String.IsNullOrWhiteSpace(model.Sites)) { sitesBuilder = SiteQuery(model.Sites); } //tag if (!String.IsNullOrWhiteSpace(model.Tags)) { tagBuilder = TagQuery(model.Tags); } //date if (!String.IsNullOrWhiteSpace(model.Dates)) { dateBuilder = DateQuery(model.Dates); } //months if (!String.IsNullOrWhiteSpace(model.Months)) { monthBuilder.Append(string.Format("MONTH(Photos.Captured) IN ({0}) ", model.Months)); } //hours if (!String.IsNullOrWhiteSpace(model.Hours)) { hourBuilder.Append(string.Format("DATEPART(hh, Photos.Captured) IN ({0}) ", model.Hours)); } //merge the builders select.Append("SELECT Photos.ID from Photos "); select.Append("LEFT JOIN CollectionPhotos ON Photos.ID = CollectionPhotos.PhotoId "); parameters.Append("(" + publicPhotosBuilder + ")"); if (collectionBuilder.Length != 0) { parameters.Append(" AND " + "(" + collectionBuilder + ")"); } if (sitesBuilder.Length != 0) { select.Append("INNER JOIN CameraSites ON Photos.Site_ID = CameraSites.ID "); parameters.Append(" AND " + "(" + sitesBuilder + ")"); } if (monthBuilder.Length != 0) { parameters.Append(" AND " + "(" + monthBuilder + ")"); } if (dateBuilder.Length != 0) { parameters.Append(" AND " + "(" + dateBuilder + ")"); } if (hourBuilder.Length != 0) { parameters.Append(" AND " + "(" + hourBuilder + ")"); } if (tagBuilder.Length != 0) { select.Append("INNER JOIN PhotoTags ON Photos.ID = PhotoTags.Photo_ID " + "INNER JOIN Tags ON PhotoTags.Tag_ID = Tags.ID "); parameters.Append(" AND " + "(" + tagBuilder + ")"); } select.Append("WHERE " + parameters); if (!String.IsNullOrWhiteSpace(model.Group)) { select.Append(" ORDER BY"); if (model.Group.Equals("site")) { select.Append(" Photos.Site_ID,"); } select.Append(" Photos.Captured"); } return select.ToString(); }
public List<long> SearchResultPhotoIds(SearchModel model) { string select = GetSearchQuery(model); List<long> ids = QuickSearch(select); return ids; }
public ActionResult Index(long collectionId = -1, string tag = "", string site = "", string year = "") { SearchModel model = new SearchModel(); model.AvailableTags = PhotoService.GetTagNames(); model.SiteNames = SearchService.GetSiteNames(); Phocalstream_Shared.Data.Model.Photo.User User = UserRepository.First(u => u.ProviderID == this.User.Identity.Name); if (User != null) { UserCollectionList userCollectionModel = new UserCollectionList(); userCollectionModel.User = User; userCollectionModel.Collections = CollectionRepository.Find(c => c.Owner.ID == User.ID && c.Site == null && c.Type == CollectionType.USER, c => c.Photos).ToList(); model.UserCollections = userCollectionModel; ViewBag.UserId = User.ID; } Collection collection = CollectionRepository.Find(c => c.ID == collectionId).FirstOrDefault(); if (collection != null && !collection.Public && collection.Type == CollectionType.USER) { // If the collection is a user collection, and it does not belong to current user if (User == null || collection.Owner.ID != User.ID) { collection = null; } } if (collection != null) { ViewBag.CollectionId = collection.ID; } ViewBag.Tag = tag; ViewBag.Site = site; ViewBag.Year = year; return View(model); }