/// <summary>Creates an instance for the given language.</summary> /// <param name="culture">The culture.</param> /// <returns>A repository.</returns> public IRecipeRepository ForCulture(CultureInfo culture) { Contract.Ensures(Contract.Result<IRecipeRepository>() != null); IRecipeRepository repository = new RecipeRepository(this.serviceClient); repository.Culture = culture; return repository; }
public MainViewModel(ILocalDataService localDataService, INavigationService navigationService) { _localDataService = localDataService; _navigationService = navigationService; _recipeRepository = new RecipeRepository(); }
public Collector(IDatabaseContext context) { _context = context; Items = new ItemRepository(_context); Ingredients = new IngredientRepository(_context); Foodplans = new FoodplanRepository(_context); Shoppinglists = new ShoppinglistRepository(_context); Recipes = new RecipeRepository(_context); Users = new UserRepository(_context); }
/// <summary>Creates an instance for the given language.</summary> /// <param name="culture">The culture.</param> /// <returns>A repository.</returns> public IRecipeRepository ForCulture(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException("culture", "Precondition: culture != null"); } IRecipeRepository repository = new RecipeRepository(this.serviceClient); repository.Culture = culture; return repository; }
public HttpResponseMessage AddRecipe(RecipeDto recipe) { var recipeRepository = new RecipeRepository(); var success = recipeRepository.Create(recipe); if (success) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not process order, please try again later... ")); }
public ActionResult Edit(int id, RecipeDto recipe) { if (!ModelState.IsValid) { return(View(recipe)); } var repo = new RecipeRepository(); repo.Update(id, recipe); return(RedirectToAction("Index")); }
public HttpResponseMessage AddRecipe(RecipeDto recipe) { var repository = new RecipeRepository(); var result = repository.Create(recipe); if (result) { return(Request.CreateResponse(HttpStatusCode.Created)); } ; return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not create recipe")); }
public ViewResult AddRecipe(Recipe userRecipe) { if (ModelState.IsValid) { RecipeRepository.AddSubmitted(userRecipe); ModelState.Clear(); return(View()); } else { return(View()); } }
public ActionResult Delete(int id) { RecipeRepository recipeRepository = new RecipeRepository(); Recipe recipe = new Recipe(); //finds requested recipe using (recipeRepository) { recipe = recipeRepository.SelectOne(id); } return(View(recipe)); }
public static int FilterAndSaveToDatabase(IEnumerable <RecipeParse> parses) { using (var itemRepo = new ItemRepository()) using (var recipeRepo = new RecipeRepository(itemRepo)) { var wrappers = Filter(Filter(parses).Select(p => BuildWrapper(p, itemRepo, recipeRepo))); foreach (var w in wrappers.Where(p => p.Recipe != null)) { recipeRepo.Save(w.Recipe); } return(wrappers.Count(p => p.Recipe != null)); } }
public void Load_After_IsModifiedShouldBeFalse() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_OK.txt"); typeof(RecipeRepository).GetProperty("IsModified").SetValue(repository, true); // act repository.Load(); // assert Assert.IsFalse(repository.IsModified); }
public void Delete(int id) { Console.Clear(); Console.Write("Are you sure you want to delete the recipe? "); if (Validation.YesNo() == ConsoleKey.N) { return; } AamountIngredientRepository.Items.RemoveAll(r => r.IdRecipe == id); CookingStepRepository.Items.RemoveAll(r => r.IdRecipe == id); RecipeRepository.Delete(id); UnitOfWork.SaveAllData(); }
private async Task AddOrDeleteFavorite() { if (btnFavorite.Source.ToString() == "File: favorite_border.png") { btnFavorite.Source = "favorite.png"; RecipeRepository.addFavoriteAsync(DetailRecipe); } else { btnFavorite.Source = "favorite_border.png"; RecipeRepository.deleteFavoriteAsync(DetailRecipe.Title); } }
public async Task <IActionResult> Delete(string hashtag, string name) { var recipeGuid = await this.GetRecipeGuid(name); var repository = new RecipeRepository(_settings.AzureStorageConnectionString); var item = await repository.GetAsync(recipeGuid); await repository.DeleteAsync(item); var viewModel = new HashtagLineViewModel(hashtag); return(Redirect(UrlBuilder.GetUrl(hashtag))); }
public async Task <IActionResult> Edit(string hashtag, string name) { Guid recipeGuid = await this.GetRecipeGuid(name); var repository = new RecipeRepository(_settings.AzureStorageConnectionString); var item = await repository.GetAsync(recipeGuid); item.ProcessRecipe(); var viewModel = new RecipeEditViewModel(hashtag, item); return(View(viewModel)); }
public IndexModel() { rr = new RecipeRepository(); Sl = new List <SelectListItem>() { new SelectListItem { Value = "false", Text = "All" }, new SelectListItem { Value = "true", Text = "Vegetarian" } }; }
public UserMenuService(KitchenMasterDbContext dbContext, CurrentUserService currentUser, RecipeRepository recipeRepository, MenuHistoryRepository menuHistoryRepository, IMapper mapper) : base(dbContext) { this._dbContext = dbContext; this._currentUser = currentUser; this._recipeRepository = recipeRepository; this._menuHistoryRepository = menuHistoryRepository; this._mapper = mapper; }
private RecipeModel Load(int id = 0) { var model = GetModel(); if (id != 0) { var recipe = RecipeRepository.GetById(id); if (recipe != null) { var category = RecipeRepository.GetCategoryById(recipe.CategoryId).HtmlDecode(); var specials = RecipeRepository.GetSpecialsForRecipe(recipe.Guid); var selectedSpecials = (from item in specials from special in model.AllSpecials where item.SpecialId == special.Id select special).ToList(); var selectedSpecialsAsString = (from item in specials from special in model.AllSpecials where item.SpecialId == special.Id select special).Aggregate(string.Empty, (current, special) => current + (special.Name.ToLower() + ", ")); var dishType = string.Empty; var avgRating = RatingRepository.GetAvarage(recipe.Guid); if (recipe.DishTypeId.HasValue) { dishType = RecipeRepository.GetDishTypeById(recipe.DishTypeId.Value); } if (selectedSpecialsAsString.EndsWith(", ")) { selectedSpecialsAsString = selectedSpecialsAsString.TrimEnd(',', ' '); } model.Recipe = recipe; model.Recipe.Name.HtmlDecode(); model.Recipe.Ingredients.HtmlDecode(); model.Recipe.Description.HtmlDecode(); model.Category = category; model.DishType = dishType; model.AvarageRating = avgRating; model.Specials = selectedSpecialsAsString; model.SelectedSpecials = selectedSpecials; SessionHandler.CurrentGuid = model.Recipe.Guid; SessionHandler.CurrentId = model.Recipe.Id.ToString(); } else { LogHandler.Log(nameof(RecipeController), LogType.Info, string.Format("Recipe with id: {0} could not be found", id)); throw new HttpException(404, "Not found"); } } return(model); }
void CreateMaterials(ItemRepository itemRepo, RecipeRepository recipeRepo, string type, List <ItemTier> tiers) { foreach (var t in tiers) { var itemName = $"{t.Prefix} {type} {t.Suffix}".Trim(); if (t.PrefixSuffixDependent) { itemName = $"{GetGemTypeToPrefix()[type]} {type}"; } var item = itemRepo.GetByName(itemName).FirstOrDefault(); if (item == null) { item = new Item(); item.Name = itemName; itemRepo.Save(item); } } var tierCount = tiers.Max(p => p.Level); for (int i = 1; i <= tierCount; i++) { var tier = tiers.FirstOrDefault(p => p.Level == i); var itemName = $"{tier.Prefix} {type} {tier.Suffix}".Trim(); if (tier.PrefixSuffixDependent) { itemName = $"{GetGemTypeToPrefix()[type]} {type}"; } var item = itemRepo.GetByName(itemName).FirstOrDefault(); if (item.MadeFrom.Any()) { continue; } var recipe = new Recipe(); recipe.Result = item; recipe.ExpectedYield = 2; var pTier = tiers.FirstOrDefault(p => p.Level == i - 1); var pItem = itemRepo.GetByName($"{pTier.Prefix} {type} {pTier.Suffix}".Trim()).FirstOrDefault(); recipe.Materials.Add(pItem, tier.PreviousTierQuantityRequired); foreach (var additional in tier.AdditionalRequired) { var aItem = itemRepo.GetByName(additional.Key).FirstOrDefault(); recipe.Materials.Add(aItem, additional.Value); } recipeRepo.Save(recipe); } }
private void export_Clicked(object sender, EventArgs e) { string sql = ""; List <Recipe> recipies = RecipeRepository.FindAll().Result; if (recipies.Count > 0) { sql += "INSERT INTO Recipe (Id,Name,Note,CreatedAt,UpdatedAt,Favourite) VALUES \n"; foreach (var item in recipies) { Console.WriteLine(item.CreatedAt); sql += "(" + item.Id + ",'" + item.Name + "','" + item.Note + "'," + item.CreatedAt.ToBinary() + "," + item.UpdatedAt.ToBinary() + "," + item.Favourite + "),\n"; } sql = sql.Remove(sql.Length - 2); sql += ";?\n"; } sql += "-- ------------------------------\n"; List <Product> products = ProductRepository.FindAll().Result; if (products.Count > 0) { sql += "INSERT INTO Product (Id,Name,Quantity,CreatedAt,UpdatedAt,RecipeId) VALUES \n"; foreach (var item in products) { sql += "(" + item.Id + ",'" + item.Name + "','" + item.Quantity.ToString().Replace(',', '.') + "'," + item.CreatedAt.ToBinary() + "," + item.UpdatedAt.ToBinary() + "," + item.RecipeId + "),\n"; } sql = sql.Remove(sql.Length - 2); sql += ";?\n"; } sql += "-- ------------------------------\n"; List <Ingredient> ingredients = IngredientRepository.FindAll().Result; if (ingredients.Count > 0) { sql += "INSERT INTO Ingredient (Id,Name,Quantity,RecipeId) VALUES \n"; foreach (var item in ingredients) { sql += "(" + item.Id + ",'" + item.Name + "'," + item.Quantity.ToString().Replace(',', '.') + "," + item.RecipeId + "),\n"; } sql = sql.Remove(sql.Length - 2); sql += ";?\n\n"; } var filename = "minticeapp_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".sql"; var fileCopyName = Path.Combine("/storage/emulated/0/MintIceApp/Export", filename); System.IO.File.WriteAllText(fileCopyName, sql); CrossToastPopUp.Current.ShowToastMessage("Baza danych została wyeksportowana (Pamięć wewnętrzna/MintIceApp/Export/" + filename); }
public void Load_After_ShouldFireRecipesChangeEvent() { // arrange RecipeRepository repository = new RecipeRepository(@"..\..\App_Data\Recipes_OK.txt"); bool eventHandled = false; repository.RecipesChangedEvent += (s, e) => { eventHandled = true; }; // act repository.Load(); // assert Assert.IsTrue(eventHandled); }
public async Task <string> GenerateShoppingCart(string words, string stores, Prj4databaseContext context) { string initString = "" + "<html>"; string endString = "</html>"; string bodystring = ""; string[] storeSplit = new string[8]; if (stores != null) { storeSplit = stores.Split(';', StringSplitOptions.RemoveEmptyEntries); } RecipeQuery query = new RecipeQuery { LoadIngredientList = true, LoadRecipeCategory = true, SearchRecipe = words, NumberOfRecipes = 1, Stores = storeSplit }; RecipeRepository recipeRepository = new RecipeRepository(context); var result = await recipeRepository.Get(query); foreach (var recipe in result) { bodystring = ""; string ingrediensstring = ""; bodystring += "<h3><strong>Indkøbsliste</strong></h3>"; bodystring += "<ul>"; foreach (var ingredient in recipe.IngredientList.Ingredient) { ingrediensstring += "<li class='p6'>" + ingredient.Name + " - " + " Købes i " + ingredient.Product.RetailChain.Name + " for " + ingredient.Product.Price + " kr. " + "</li>"; } bodystring += ingrediensstring; bodystring += "</ul>" + "</div>" + "<br style='clear:both' />" + "<ul>" + "</div>"; } return(initString + bodystring + endString); }
public void SetUp() { string ConnectionString = "Data Source=prj4-server.database.windows.net;Initial Catalog=prj4-database;User ID=maloudt;Password=Mldt1160"; SqlConnection conn = new SqlConnection(ConnectionString); conn.Open(); var options = new DbContextOptionsBuilder <Prj4databaseContext>() .UseSqlServer(conn).Options; _context = new Prj4databaseContext(options); _uut = new RecipeRepository(_context); }
public UnitOfWork() { var storagePath = AppDomain.CurrentDomain.BaseDirectory; var inMemoryService = new InMemoryService(); _fileManager = new FileManager(); var ingredientList = _fileManager.ResolveEntitiesFile(Path.Combine(storagePath, _fileManager.IngredientsFile), inMemoryService?.GetAllIngredients()); var recipeList = _fileManager.ResolveEntitiesFile(Path.Combine(storagePath, _fileManager.RecipesFile), inMemoryService?.GetAllRecipes()); var categoryList = _fileManager.ResolveEntitiesFile(Path.Combine(storagePath, _fileManager.CategoriesFile), inMemoryService?.GetAllCategories()); RecipeRepository = new RecipeRepository(recipeList, _fileManager.IngredientsFile); CategoryRepository = new CategoryRepository(categoryList, _fileManager.RecipesFile); IngredientRepository = new IngredientRepository(ingredientList, _fileManager.CategoriesFile); }
public ActionResult AddRecipe(int weekPlanId, int recipeId) { WeekItem item = new WeekItem { RecipeId = recipeId, WeekId = weekPlanId, WeekDay = String.Empty }; RecipeRepository repo = new RecipeRepository(ConnectionString); repo.InsertWeekItem(item); return(Content("200")); }
public async Task <Unit> UpdateRecipesAsync() { var recipeDetails = await RecipeRepository.GetMyRecipeDetails()(environment); Recipes = recipeDetails.Select(detail => new RecipeCellViewModel( detail, Option.Empty <int>(), new UserAction <IRecipe>(r => AddToShoppingList(r), Icon.CartAdd(), 1), new UserAction <IRecipe>(r => EditRecipe(r), Icon.Edit(), 2), new UserAction <IRecipe>(r => Task.FromResult(DeleteRecipe(r)), Icon.Delete(), 3) )); RaisePropertyChanged(nameof(Recipes)); return(Unit.Value); }
public async Task GetRecipeIngredients_OkResult() { RecipeRepository recipe = new RecipeRepository(_options, new HttpClient(), _cacheServiceMock.Object); var controller = new RecipesController(recipe, _mapper, _logger); var result = await controller.GetRecipeIngredients(12); result.Should().NotBeNull(); var okResult = result.Should().BeOfType <OkObjectResult>().Subject; Assert.True(okResult.StatusCode.Equals(200)); var model = okResult.Value.Should().BeAssignableTo <RecipeIngredientsResponse>().Subject; model.Ingredients.Should().HaveCount(4); }
public void GetById_Test() { // Arrange - Create the repository var repository = new RecipeRepository(_context); // Arrange - Setup expectations var expectedId = 1; // Act - Make the repository call repository.FullEagerLoad(); var actual = repository.GetById(expectedId); // Assert - Verify the entity VerifyEntity(actual, expectedId); }
protected async override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); var dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Project.db"); var recipeRepository = new RecipeRepository(dbPath); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); LoadApplication(new App(recipeRepository)); await TryToGetPermissions(); }
public IHttpActionResult GenShoppingList(int[] recipeIdArray) { RecipeRepository repository = new RecipeRepository(); StringBuilder IngredientNames = new StringBuilder(); Recipe recipe; foreach (var id in recipeIdArray) { recipe = repository.Get(id); IngredientNames.Append(recipe.Ingredients.Replace("\n", "")); IngredientNames.Append("\n"); } return(Ok(IngredientNames.ToString())); }
private void btnSearch_Click(object sender, EventArgs e) { var repository = new RecipeRepository(); string title = titleTextBox.Text; string category = categoryTextBox.Text; var coll = repository.Search(title, category); dataGridView1.DataSource = coll.Select(r => new { Id = r.Id, Titel = r.Title, Kategori = r.Category.Name }).ToArray(); }
public void GetRecipes_FilterListWithExact(string filters) { //Arrange var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>() .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}") .Options; var sieveOptions = Options.Create(new SieveOptions()); var fakeRecipeOne = new FakeRecipe { }.Generate(); fakeRecipeOne.RecipeTextField1 = "Alpha"; fakeRecipeOne.RecipeTextField2 = "Bravo"; fakeRecipeOne.RecipeIntField1 = 5; var fakeRecipeTwo = new FakeRecipe { }.Generate(); fakeRecipeTwo.RecipeTextField1 = "Charlie"; fakeRecipeTwo.RecipeTextField2 = "Delta"; fakeRecipeTwo.RecipeIntField1 = 6; var fakeRecipeThree = new FakeRecipe { }.Generate(); fakeRecipeThree.RecipeTextField1 = "Echo"; fakeRecipeThree.RecipeTextField2 = "Foxtrot"; fakeRecipeThree.RecipeIntField1 = 7; //Act using (var context = new RecipeDbContext(dbOptions)) { context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree); context.SaveChanges(); var service = new RecipeRepository(context, new SieveProcessor(sieveOptions)); var recipeRepo = service.GetRecipes(new RecipeParametersDto { Filters = filters }); //Assert recipeRepo.Should() .HaveCount(1); context.Database.EnsureDeleted(); } }
public ActionResult Index(string sortOrder, int?page) { RecipeRepository recipeRepository = new RecipeRepository(); //Creates a unique list of beer Styles ViewBag.Styles = ListOfStyles(sortOrder); IEnumerable <Recipe> recipes; //using statement to populate recipes and clean up after itself using (recipeRepository) { recipes = recipeRepository.SelectAll(sortOrder) as IList <Recipe>; } // sort by name unless posted as a new sort switch (sortOrder) { case "NAME": recipes = recipes.OrderBy(s => s.Name); break; case "STYLE": recipes = recipes.ToList().OrderBy(s => s.Style); break; case "ABV": recipes = recipes.ToList().OrderBy(s => s.ABV); break; case "IBU": recipes = recipes.ToList().OrderBy(s => s.IBU); break; default: recipes = recipes.ToList().OrderBy(s => s.Name); break; } //PAGEINATE int pageSize = 10; int pageNumber = (page ?? 1); recipes = recipes.ToPagedList(pageNumber, pageSize); return(View(recipes)); }
public IEnumerable <Recipe> Get(string query) { try { query = query.ToLower(); return(RecipeRepository.GetRecipes() .Where(p => p.Title.ToLower().StartsWith(query)) .Select(r => new Recipe(r.Id, r.Title, r.ImagePath, r.Rating)) .ToList()); } catch (Exception) { throw new HttpResponseException(HttpStatusCode.BadRequest); } }
public void Setup() { repos = new RecipeRepository("server=localhost;user=root;password=papaloona;database=vitatop"); }
public RecipeController(RecipeRepository recipeRepository) { _recipeRepository = recipeRepository; }
public RecipeController() { _repository = ObjectFactory.GetRepositoryInstance<Recipe, RecipeRepository>(new DbContextFactory().GetFitnessRecipeEntities()); }
public RecipesController() { this.repository = new RecipeRepository(); }
public IngredientViewModel() { _entities = new DbContextFactory().GetFitnessRecipeEntities(); _recipeRepository = new RecipeRepository(_entities); }
public CategoriesController() { this.repository = new RecipeRepository(); }
public RecipeController() { RecipeRepository = new RecipeRepository(); }
public void Setup() { repository = new RecipeRepository(); manager = new RecipeManager(repository); }
public RecipesViewModel(IRecipesService recipesService) { _recipesService = recipesService; _recipeRepository = new RecipeRepository(); }
public IngredientsController() { this.repository = new RecipeRepository(); }
protected override void LoadTestData() { _recipeRepository = new RecipeRepository(); PrepareProducts(); PrepareWorkingProcedure(); }