private async Task <ProcessResult <List <Photograph> > > GetPhotoNameUpdatesAsync(int categoryId, string namingThemeCode) { string[] existingNames = await _db.Photographs .Where(p => p.Category.CategoryId == categoryId && !string.IsNullOrEmpty(p.AnonymousPhotoName)) .Select(p => p.AnonymousPhotoName) .ToArrayAsync(); List <string> potentialNames = PhotoNamingThemes .GetThemeItems(namingThemeCode) .Minus(existingNames) .InRandomSequence(); List <Photograph> photosToUpdate = await _db.Photographs .Where(p => p.Category.CategoryId == categoryId && string.IsNullOrEmpty(p.AnonymousPhotoName)) .ToListAsync(); photosToUpdate = photosToUpdate.InRandomSequence(); ProcessResult <List <Photograph> > result = new ProcessResult <List <Photograph> >(); if (photosToUpdate.Count > potentialNames.Count) { result.AddError("Not enough anonymous photo names to assign for the number of photos in this category"); } else { int itemNo = 0; foreach (Photograph photo in photosToUpdate) { photo.AnonymousPhotoName = potentialNames[itemNo]; itemNo++; } result.SetResult(photosToUpdate); } return(result); }
public CategoryViewModel BuildViewModelDropdownCriteria(CategoryViewModel viewModel) { viewModel.StatusCodeTypes = CategoryStatusCodes .GetAll() .Select(c => new KeyValuePair <string, string>(c, CategoryStatusCodes.GetStatusText(c))); viewModel.PhotoNamingThemeTypes = PhotoNamingThemes .ThemeCodes .GetAll() .Select(p => new KeyValuePair <string, string>(p, PhotoNamingThemes.GetThemeDescription(p))); return(viewModel); }