public List <ImageWithDate> SearchImagesForUser(int userId, string searchString = "") { if (_userServices.GetUser(userId).Membership == "Administrator") { return(SearchImages(searchString)); } var user = _userServices.GetUser(userId); if (user.ImageManagementEnabled == 0) { return(SearchImages(searchString)); } var listOfImages = new List <ImageEntity>(); var userManagedImages = _userServices.GetUserImageManagements(userId); listOfImages.AddRange( userManagedImages.Select( managedImage => _uow.ImageRepository.GetFirstOrDefault( i => i.Name.Contains(searchString) && i.Id == managedImage.ImageId))); var listWithDate = new List <ImageWithDate>(); foreach (var image in listOfImages) { var imageWithDate = new ImageWithDate(); imageWithDate.Id = image.Id; imageWithDate.Name = image.Name; imageWithDate.Environment = image.Environment; imageWithDate.Approved = image.Approved; imageWithDate.LastUsed = new AuditLogServices().GetImageLastUsedDate(image.Id); imageWithDate.ClassificationId = image.ClassificationId; listWithDate.Add(imageWithDate); } return(listWithDate); }
public List <ImageWithDate> SearchImages(string searchString = "") { var images = _uow.ImageRepository.Get(i => i.Name.Contains(searchString)); var listWithDate = new List <ImageWithDate>(); foreach (var image in images) { var imageWithDate = new ImageWithDate(); imageWithDate.Id = image.Id; imageWithDate.Name = image.Name; imageWithDate.Environment = image.Environment; imageWithDate.Approved = image.Approved; imageWithDate.LastUsed = new AuditLogServices().GetImageLastUsedDate(image.Id); imageWithDate.ClassificationId = image.ClassificationId; imageWithDate.LastUploadGuid = image.LastUploadGuid; imageWithDate.Type = image.Type; imageWithDate.Description = image.Description; listWithDate.Add(imageWithDate); } return(listWithDate); }
public List <ImageWithDate> Search(DtoSearchFilterCategories filter) { if (filter.Limit == 0) { filter.Limit = Int32.MaxValue; } var images = _uow.ImageRepository.Get(x => x.Name.Contains(filter.SearchText)).OrderBy(x => x.Name).ToList(); var categoryFilterIds = new List <int>(); foreach (var catName in filter.Categories) { var category = _uow.CategoryRepository.GetFirstOrDefault(x => x.Name.Equals(catName)); if (category != null) { categoryFilterIds.Add(category.Id); } } var toRemove = new List <EntityImage>(); if (filter.CategoryType.Equals("Any Category")) { //do nothing, keep all } else if (filter.CategoryType.Equals("And Category")) { foreach (var image in images) { var gCategories = GetImageCategories(image.Id); if (gCategories == null) { continue; } if (filter.Categories.Count == 0) { if (gCategories.Count > 0) { toRemove.Add(image); continue; } } foreach (var id in categoryFilterIds) { if (gCategories.Any(x => x.CategoryId == id)) { continue; } toRemove.Add(image); break; } } } else if (filter.CategoryType.Equals("Or Category")) { foreach (var image in images) { var pCategories = GetImageCategories(image.Id); if (pCategories == null) { continue; } if (filter.Categories.Count == 0) { if (pCategories.Count > 0) { toRemove.Add(image); continue; } } var catFound = false; foreach (var id in categoryFilterIds) { if (pCategories.Any(x => x.CategoryId == id)) { catFound = true; break; } } if (!catFound) { toRemove.Add(image); } } } foreach (var p in toRemove) { images.Remove(p); } var listWithDate = new List <ImageWithDate>(); foreach (var image in images) { var auditLog = _uow.AuditLogRepository.Get( x => x.ObjectType == "Image" && x.ObjectId == image.Id && (x.AuditType.ToString().ToLower().Contains("deploy") || x.AuditType.ToString().ToLower().Contains("upload") || x.AuditType.ToString().ToLower().Contains("push") || x.AuditType.ToString().ToLower().Contains("multicast"))) .OrderByDescending(x => x.Id) .FirstOrDefault(); var imageWithDate = new ImageWithDate(); imageWithDate.Id = image.Id; imageWithDate.Name = image.Name; imageWithDate.Environment = image.Environment; imageWithDate.Protected = image.Protected; imageWithDate.Enabled = image.Enabled; imageWithDate.IsVisible = image.IsVisible; if (auditLog != null) { if (auditLog.DateTime != null) { imageWithDate.LastUsed = auditLog.DateTime; } } imageWithDate.LastUploadGuid = image.LastUploadGuid; imageWithDate.Type = image.Type; imageWithDate.Description = image.Description; listWithDate.Add(imageWithDate); } return(listWithDate.Take(filter.Limit).ToList()); }