Example #1
0
        public async Task <IActionResult> WaitConfirm()
        {
            var recipes = await _recipeRepository.GetAllAsync(x => !x.IsDeleted && !x.IsConfirmed, x => x.User, x => x.FoodCategory);

            if (recipes == null)
            {
                return(NotFound());
            }

            var recipeDto = _mapper.Map <IEnumerable <RecipeIndexDto> >(recipes);

            foreach (var recipe in recipeDto)
            {
                var recipeSelected = recipes.FirstOrDefault(r => r.Id == recipe.Id);
                recipe.FoodCategoryName = recipeSelected.FoodCategory.CategoryName;
                recipe.UserName         = recipeSelected.User.UserName;
            }

            var model = new RecipeIndexViewModel
            {
                Recipes = recipeDto
            };

            return(View(model));
        }
Example #2
0
        public RecipeIndexViewModel GetRecipeIndexViewModel()
        {
            RecipeIndexViewModel vm = new RecipeIndexViewModel();
            IDbConnection        conn;

            conn       = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString);
            vm.Recipes = conn.Query <Recipe>("SELECT * FROM Recipe").ToList();
            return(vm);
        }
Example #3
0
        public ActionResult Index()
        {
            using (var context = new ApplicationDbContext())
            {
                var recipeService = new RecipeService(context, HttpContext);
                var recipes       = recipeService.GetAllAvailableRecipes();

                var viewModel = new RecipeIndexViewModel(recipes);

                return(View(viewModel));
            }
        }
Example #4
0
        public async Task <IActionResult> RecipeIndexResult(RecipeSearchViewModel model)
        {
            var response = await _recipeClient.GetAllRecipes(model.ingredient, model.title, model.page);

            var viewModel = new RecipeIndexViewModel();

            viewModel.results = response.results
                                .Select(response => new ResultsViewModel()
            {
                title = response.title, href = response.href, thumbnail = response.thumbnail
            })
                                .ToList();

            return(View(viewModel));
        }
Example #5
0
        public ActionResult Edit(FormCollection collection)
        {
            var rivm = new RecipeIndexViewModel
            {
                RecipeId   = Int32.Parse(collection["RecipeId"]),
                BeerDesc   = collection["BeerDesc"],
                BeerMake   = collection["BeerMake"],
                BeerType   = collection["BeerType"],
                OwnerId    = 1,//Degistirilecek
                OwnerNick  = "DeniizBb",
                RecipeName = collection["RecipeName"]
            };

            service.EditRecipe(rivm);
            return(RedirectToAction("Index"));
        }
Example #6
0
        public RecipeIndexViewModel GetById(int recipeId)
        {
            //Do validation here
            var item = rp.GetById(recipeId);

            var returnItem = new RecipeIndexViewModel
            {
                RecipeId    = item.RecipeId,
                RecipeName  = item.Name,
                BeerDesc    = item.Description,
                BeerMake    = item.Making,
                BeerType    = orp.GetBeerType(item.BeerTypeId).BeerType1,
                OwnerNick   = mrp.GetById(item.PostedBy).Username,
                Ingredients = irp.GetRecipeIngredients(item.RecipeId)
            };

            return(returnItem);
        }
Example #7
0
        public ActionResult Create(FormCollection collection)
        {
            int ret    = -1;
            var memSrv = new MemberService();

            if (Session["Username"] != null)
            {
                var rivm = new RecipeIndexViewModel
                {
                    BeerDesc   = collection["BeerDesc"],
                    BeerMake   = collection["BeerMake"],
                    BeerType   = collection["BeerType"],
                    OwnerId    = memberService.GetByUsername(Session["Username"].ToString()).MemberId.GetValueOrDefault(),
                    OwnerNick  = Session["Username"].ToString(),
                    RecipeName = collection["RecipeName"]
                };
                ret = service.CreateRecipe(rivm, false);
            }
            else if (Session["Admin"] != null)
            {
                var rivm = new RecipeIndexViewModel
                {
                    BeerDesc   = collection["BeerDesc"],
                    BeerMake   = collection["BeerMake"],
                    BeerType   = collection["BeerType"],
                    OwnerId    = memberService.GetByUsername(Session["Admin"].ToString()).MemberId.GetValueOrDefault(),
                    OwnerNick  = Session["Admin"].ToString(),
                    RecipeName = collection["RecipeName"]
                };
                ret = service.CreateRecipe(rivm, true);
            }

            if (collection["To"] == "Create" || ret == -1) // error sayfasına döndür
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("AddIngredient", new { id = ret }));
            }
        }
Example #8
0
 public int CreateRecipe(RecipeIndexViewModel newRecipe, bool isGlobal)
 {
     //PostedBy will come from session
     //Ingredients will be displayed
     try
     {
         return(rp.Create(new Recipe
         {
             Description = newRecipe.BeerDesc,
             IsActive = true,
             IsGlobal = isGlobal,
             Making = newRecipe.BeerMake,
             Name = newRecipe.RecipeName,
             BeerTypeId = CheckAndCreateBeerType(newRecipe.BeerType),
             PostedBy = newRecipe.OwnerId
         }));
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
        public void BeforeAll()
        {
            // Set up dependencies for controller
            this._recipesFromProvider = Builder<Recipe>.CreateListOfSize(10).Build();
            var recipeProvider = MockRepository.GenerateStub<IRepository<Recipe,string>>();
            recipeProvider.Stub(p => p.Get()).Return(this._recipesFromProvider);

            this._categoriesFromProvider = Builder<Category>.CreateListOfSize(20).Build();
            var categoryProvider = MockRepository.GenerateStub<IRepository<Category,string>>();
            categoryProvider.Stub(p => p.Get()).Return(this._categoriesFromProvider);

            var controller = new RecipeController(recipeProvider,
                                                  categoryProvider,
                                                  new AutoMapperMapper<Recipe, RecipeViewModel>(),
                                                  new AutoMapperMapper<RecipeViewModel, Recipe>(),
                                                  new AutoMapperMapper<Category, CategoryViewModel>(),
                                                  MockRepository.GenerateStub<IImageProvider>(),
                                                  MockRepository.GenerateStub<IFileProvider>(),
                                                  MockRepository.GenerateStub<IFeatureUsageNotifier>()
                );

            this._viewResult = controller.Index(string.Empty);
            this._viewModel = this._viewResult.Model as RecipeIndexViewModel;
        }
Example #10
0
 public bool EditRecipe(RecipeIndexViewModel newRecipe)
 {
     //PostedBy will come from session
     //Ingredients will be displayed
     try
     {
         rp.Edit(new Recipe
         {
             RecipeId    = newRecipe.RecipeId,
             Description = newRecipe.BeerDesc,
             IsActive    = true,
             IsGlobal    = true,
             Making      = newRecipe.BeerMake,
             Name        = newRecipe.RecipeName,
             BeerTypeId  = CheckAndCreateBeerType(newRecipe.BeerType),
             PostedBy    = 1
         });
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Example #11
0
        public IActionResult Index()
        {
            RecipeIndexViewModel vm = GetRecipeIndexViewModel();

            return(View(vm));
        }