public static async Task <Unit> GetUnitAsync(CocktailsContext _context, int unitId) { var unit = await _context.Unit .SingleOrDefaultAsync(m => m.Id == unitId); return(unit); }
public static async Task <Recipe> GetRecipeAsync(CocktailsContext _context, Guid recipeId) { var recipe = await _context.Recipe .SingleOrDefaultAsync(m => m.Id == recipeId); return(recipe); }
public static async Task <Component> GetComponentAsync(CocktailsContext _context, Guid componentId) { var component = await _context.Component .SingleOrDefaultAsync(m => m.Id == componentId); return(component); }
public static async Task <List <MixType> > GetMixTypesAsync(CocktailsContext _context) { var mixTypes = await _context.MixType .ToListAsync(); return(mixTypes); }
public static async Task <List <Library> > GetLibrariessAsync(CocktailsContext _context) { var libraries = await _context.Library .ToListAsync(); return(libraries); }
public static async Task <MixType> GetMixTypeAsync(CocktailsContext _context, int mixTypeId) { var mixType = await _context.MixType .SingleOrDefaultAsync(mbox => mbox.Id == mixTypeId); return(mixType); }
public static async Task <Library> GetLibraryAsync(CocktailsContext _context, Guid libraryId) { var library = await _context.Library .SingleOrDefaultAsync(m => m.Id == libraryId); return(library); }
public static async Task <ComponentType> GetComponentTypeAsync(CocktailsContext _context, int componentTypeId) { var componentType = await _context.ComponentType .SingleOrDefaultAsync(m => m.Id == componentTypeId); return(componentType); }
public static async Task <Ingredient> GetIngredientAsync(CocktailsContext _context, Guid ingredientId) { var ingredient = await _context.Ingredient .SingleOrDefaultAsync(m => m.Id == ingredientId); return(ingredient); }
public static async Task <List <Unit> > GetUnitsAsync(CocktailsContext _context) { var units = await _context.Unit .ToListAsync(); return(units); }
public RecipesController(CocktailsContext context, IRecipeService recipeService, ILibraryService libraryService) { _context = context; _recipeService = recipeService; _libraryService = libraryService; }
public static async Task <List <Recipe> > GetRecipesAsync(CocktailsContext _context) { var recipes = await _context.Recipe .OrderBy(t => t.Name) .ToListAsync(); return(recipes); }
public LibraryImporterTests() { var builder = new DbContextOptionsBuilder <CocktailsContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); _db = new CocktailsContext(builder.Options); _sut = new LibraryImporter(_db); }
public static async Task <List <Ingredient> > GetIngredientsAsync(CocktailsContext _context) { var ingredients = await _context.Ingredient .OrderBy(t => t.Number) .ToListAsync(); return(ingredients); }
public static async Task <List <ComponentType> > GetComponentTypesAsync(CocktailsContext _context) { var componentTypes = await _context.ComponentType .OrderBy(t => t.Name) .ToListAsync(); return(componentTypes); }
public static async Task <ComponentViewModel> GetComponentViewModelAsync(CocktailsContext _context, Guid id) { var component = await GetComponentAsync(_context, id); var componentType = await GetComponentTypeAsync(_context, component.ComponentTypeId); var model = new ComponentViewModel(component, componentType); return(model); }
public static async Task <List <Ingredient> > GetIngredientsByRecipeAsync(CocktailsContext _context, Guid recipeId) { var recipe = GetRecipe(_context, recipeId); var ingredients = await _context.Ingredient .Where(t => t.RecipeId == recipeId) .OrderBy(t => t.Number) .ToListAsync(); return(ingredients); }
public static List <SelectListItem> GetUnitSelectListItems(CocktailsContext _context) { var units = GetUnits(_context); var items = units.ConvertAll(t => new SelectListItem() { Text = t.Name, Value = t.Id.ToString() }); return(items); }
private void InitContext() { var rand = new Random(); CocktailsContext = new CocktailsContext(CreateContextOptions()); var flavors = Enumerable.Range(1, 100) .Select(i => new Flavor { Id = Guid.NewGuid(), Name = $"Flavor{i}", ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next()) }); var categories = Enumerable.Range(1, 100) .Select(i => new Category { Id = Guid.NewGuid(), Name = $"Category{i}", ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next()) }); CocktailsContext.Flavors.AddRange(flavors); CocktailsContext.Categories.AddRange(categories); CocktailsContext.SaveChanges(); var ingredients = Enumerable.Range(1, 100) .Select(i => new Ingredient { Id = Guid.NewGuid(), Name = $"Ingredient{i}", FlavorId = CocktailsContext.Flavors.ToArray()[i - 1].Id, CategoryId = CocktailsContext.Categories.ToArray()[i - 1].Id, ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next()) }); CocktailsContext.Ingredients.AddRange(ingredients); CocktailsContext.SaveChanges(); var cocktails = Enumerable.Range(1, 100) .Select(i => new Cocktail { Id = Guid.NewGuid(), Name = $"Cocktail{i}", ModifiedDate = DateTimeOffset.UtcNow.AddTicks(rand.Next()) }); CocktailsContext.Cocktails.AddRange(cocktails); CocktailsContext.SaveChanges(); }
public static List <SelectListItem> GetComponentTypeSelectListItems(CocktailsContext _context) { var componentTypes = GetComponentTypes(_context); var items = componentTypes.ConvertAll(t => new SelectListItem() { Text = t.Name, Value = t.Id.ToString() }); return(items); }
public static async Task <IngredientViewModel> GetIngredientViewModelAsync(CocktailsContext _context, Guid id) { var ingredient = await GetIngredientAsync(_context, id); var recipe = await GetRecipeAsync(_context, ingredient.RecipeId); var component = await GetComponentAsync(_context, ingredient.ComponentId); var unit = await GetUnitAsync(_context, ingredient.UnitId); var model = new IngredientViewModel(ingredient, recipe, component, unit); return(model); }
public RecipeImporterTests() { var builder = new DbContextOptionsBuilder <CocktailsContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); _db = new CocktailsContext(builder.Options); _sut = new RecipeImporter(_db); _db.Library.Add(new Library { Id = LibraryId, Name = LibraryName }); _db.SaveChanges(); }
public async Task GetFlavorWithCorrectId() { var id = Guid.NewGuid(); var flavor = new Flavor { Id = id, Name = "flavor" }; CocktailsContext.Add(flavor); CocktailsContext.SaveChanges(); var result = await _repository.GetSingleAsync(x => x.Where(y => y.Id == id), _token); Assert.IsNotNull(result); Assert.AreEqual(flavor.Id, result.Id); Assert.AreEqual(flavor.Name, result.Name); }
public static async Task <RecipeViewModel> GetRecipeViewModelAsync(CocktailsContext _context, Guid id, bool includeIngredients = false) { var recipe = await GetRecipeAsync(_context, id); var library = await GetLibraryAsync(_context, recipe.LibraryId); var mixType = await GetMixTypeAsync(_context, recipe.MixTypeId); var model = new RecipeViewModel(recipe, library, mixType); if (includeIngredients) { model.IngredientViewModels = await GetIngredientViewModelsByRecipeAsync(_context, id); } return(model); }
public void GetCocktailsByNameTest() { const string nameKeyword = "Name "; var item1 = CocktailsContext.Cocktails.ToArray()[0]; var item2 = CocktailsContext.Cocktails.ToArray()[1]; item1.Name = nameKeyword + 1; item2.Name = nameKeyword + 2; CocktailsContext.SaveChanges(); var result = QueryFunctions.CocktailsByNameFunction(CocktailsContext.Cocktails, nameKeyword).ToArray(); Assert.AreEqual(2, result.Length); Assert.Contains(item1, result); Assert.Contains(item2, result); }
public static List <SelectListItem> GetIngredientSelectListItems(CocktailsContext _context) { var ingredients = GetIngredients(_context); var items = new List <SelectListItem>(); foreach (var ingredient in ingredients) { var component = GetComponent(_context, ingredient.ComponentId); items.Add(new SelectListItem() { Text = ingredient.Number.ToString() + " " + component.Name, Value = ingredient.Number.ToString() }); } return(items); }
public IngredientsController(CocktailsContext context) { _context = context; }
public ComponentTypesController(CocktailsContext context) { _context = context; }
public UnitImporter(CocktailsContext context) { _context = context; }
public ComponentImporter(CocktailsContext context) { _context = context; }