public IActionResult CreateRecipe([Bind("Id,Name,RecipeDescription,RecipeCategories,RecipeCategory,GlobalError")] RecipeModel recipe_model) { if (ModelState.IsValid && HttpContext.Request.Form.Files.Count > 0) { var recipe = _recipeRepository.GetByName(recipe_model.Name); if (recipe == null) { recipe = CastModelToRecipe(recipe_model); var pic = HttpContext.Request.Form.Files[0]; using (var ms = new MemoryStream()) { pic.CopyTo(ms); recipe.Picture = ms.ToArray(); } recipe.Creator = GetCurrentUser(); recipe.AddDate = DateTime.Now; recipe.ChangeDate = DateTime.Now; var recipe_id = _recipeRepository.Create(recipe); return(RedirectToRecipes(recipe_id)); } ModelState.AddModelError("GlobalError", "Такой рецепт уже существует."); } recipe_model.RecipeCategories = _recipeCategoryRepository.Get(); return(View(recipe_model)); }
public ActionResult Create(RecipeDto recipe) { //Save it to the database var repo = new RecipeRepository(); repo.Create(recipe); return(RedirectToAction("Index")); }
public HttpResponseMessage AddRecipe(RecipeDto recipe) { var recipeRepository = new RecipeRepository(); var result = recipeRepository.Create(recipe); return((result) ? Request.CreateResponse(HttpStatusCode.Created) : Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not create recipe. Please try again.")); }
public ActionResult Post([FromBody] Recipe value) { try { return(Ok(_repo.Create(value))); } catch (Exception e) { return(BadRequest(e)); } }
public HttpResponseMessage AddRecipe(RecipesDto recipe) { var recipeRepository = new RecipeRepository(); var createRecipe = recipeRepository.Create(recipe); if (createRecipe) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Sorry we could not create a recipe at this time, please try again later.")); }
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 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 int Create(RecipeBL recipe, List <CategoryRecipeBL> listOfCategories, List <SubcategoryRecipeBL> listOfSubcategories) { RatingService r = new RatingService(); var ratingID = r.CreateEmptyRating(); var recipeDAL = new Recipe() { Name = recipe.Name, Description = recipe.Description, LongDescription = recipe.LongDescription, RatingID = ratingID, PictureLocation = recipe.PictureLocation, PrepTime = recipe.PrepTime, CookTime = recipe.CookTime }; int id = recipeRepository.Create(recipeDAL); List <CategoryRecipe> categoriesRecipe = new List <CategoryRecipe>(); List <SubcategoryRecipe> subcategoriesRecipe = new List <SubcategoryRecipe>(); foreach (var c in listOfCategories) { categoriesRecipe.Add(new CategoryRecipe { CategoryID = c.CategoryID, RecipeID = id }); } foreach (var c in categoriesRecipe) { categoryRecipeRepository.Create(c); } foreach (var s in listOfSubcategories) { subcategoriesRecipe.Add(new SubcategoryRecipe { SubcategoryID = s.SubcategoryID, RecipeID = id }); } foreach (var s in subcategoriesRecipe) { subcategoryRecipeRepository.Create(s); } return(id); }
public void Add(int idCategory) { int idRecipe = RecipeRepository.Items.Count() > 0 ? RecipeRepository.Items.Max(x => x.Id) + 1 : 1; Console.WriteLine($"\n The recipe will be added to the category: {CategoryRepository.Get(idCategory).Name}"); Console.Write("\n Enter the name of the recipe: "); string nameRecipe = RecipeRepository.IsNameMustNotExist(Console.ReadLine()); Console.Write("\n Enter recipe description: "); string description = Validation.NullOrEmptyText(Console.ReadLine()); RecipeRepository.Create(new Recipe() { Id = idRecipe, Name = nameRecipe, Description = description, IdCategory = idCategory }); UnitOfWork.SaveAllData(); }
public ActionResult Create(Recipe recipe, HttpPostedFileBase imageLocation) { if (ModelState.IsValid) { recipe.Id = Guid.NewGuid(); if (imageLocation != null) { recipe.ImageLocation = ImageRepository.Save(imageLocation.ContentType, imageLocation.InputStream).AbsoluteUri; } RecipeRepository.Create(recipe); SearchProvider.AddToIndex(recipe); return(RedirectToAction("Index")); } return(View(recipe)); }
public static async Task GenerateTestData(CookingBookContext cookingBookContext) { var appUser = new ApplicationUser(); appUser.UserName = "******"; appUser.Email = "*****@*****.**"; appUser.PasswordHash = "AGwu0Rve83bj8IDQ6TYxjEguZBtQfOCyOmJZfUAAg/lYiLCQasQPE9yp+pi/cIl5+w=="; var recipeRepository = new RecipeRepository(cookingBookContext); var firstRecipe = new Recipe { Votes = 0, Description = @"Although we can’t lay claim to the “put it in a bag and shake” method used to cook these pork cutlets, we’ll acknowledge that it’s pretty genius. That’s because it makes breading meat about as quick and easy as can be (and yes, it’s so juicy). After it’s covered with breadcrumbs, the pork is fried in a pan ’til golden and served with toasted garlic bread and a crisp salad. If that sounds like a lot, fret not—this meal can be made in as little as 20 minutes.", Name = "Shake it Up! Pork Cutlets", AmountOfTime = new TimeSpan(0, 25, 0), Servings = 4, Steps = @"1)Wash and dry all produce. Adjust rack to upper position and preheat oven to 450 degrees. Mince garlic. Place panko in a gallon-sized zip-close bag and season with salt and pepper (we used 2 tsp kosher salt). 2)Place sour cream in a medium bowl, then add pork and toss to coat. Place coated pork and fry seasoning in bag with panko and seal to close. Shake until pork is evenly coated. TIP: You may need to move around cutlets in bag, pressing with your hands to spread out panko and make it stick. 3)Heat a ¼-inch layer of oil in a large pan over medium-high heat (use a nonstick pan if you have one). Halve and core apples, then slice into thin half-moons. Thinly slice celery on a diagonal. Split ciabattas in half (as if you were making sandwiches). 4)Once oil is hot (it should sizzle if you add a breadcrumb), remove pork from bag (discard any panko that doesn’t stick). Add half the pork to pan and cook until panko is golden brown and crisp, 2-3 minutes per side. Transfer to a paper-towel-lined plate and set aside. Repeat with remaining pork. 5)Meanwhile, place 6 TBSP butter and garlic in a small, microwave-safe bowl. Microwave on high until butter melts, about 30 seconds. Place ciabatta halves cut-side up on a baking sheet and drizzle with butter mixture. Toast in oven until crisp and golden, about 5 minutes. Halve on a diagonal to create triangles., 6)While ciabattas toast, toss together apples, celery, arugula, sunflower seeds, 2 TBSP olive oil, and lemon juice to taste in a medium bowl. Season with salt and pepper. Divide pork, salad, and ciabattas between plates.", RecipeIngredientDetails = new List<RecipeIngredientDetail> { new RecipeIngredientDetail{ IngredientName = "Garlic", QuantityDescription = "2 gloves" }, new RecipeIngredientDetail{ IngredientName = "Sour Cream", QuantityDescription = "4 tablespoons"}, new RecipeIngredientDetail{ IngredientName = "Celery", QuantityDescription = "6 units" }, new RecipeIngredientDetail{ IngredientName = "Arugula", QuantityDescription = "4 ounces" }, }, ImageUrl = "https://res.cloudinary.com/hellofresh/image/upload/f_auto,fl_lossy,q_80,w_auto:100:1280/v1/hellofresh_s3/image/w36-r5-family-73aeb975.jpg", Author = appUser, AddedOn = DateTime.Now }; var secondRecipe = new Recipe { Votes = 0, Description = @"Not many tacos can boast that they’re rich in vitamin A. Ours, however, are full of it, thanks to tender roasted cubes of sweet potato. They’re joined by black beans and a zesty avocado crema for some of the most delectable veggie goodness to be found inside the fold of a tortilla. You could say that they bring their A-game in every single way.", Name = "Sweet Potato and Black Bean Tacos", AmountOfTime = new TimeSpan(0, 40, 0), Servings = 4, Steps = @"1)Wash and dry all produce. Adjust rack to middle position and preheat oven to 400 degrees. Cut sweet potatoes into ½-inch cubes. Toss on a baking sheet with 1 TBSP olive oil and a pinch of salt and pepper. Roast in oven until tender and lightly browned, about 20 minutes. 2)Meanwhile, halve, peel, and dice onion. Pick cilantro leaves from stems; discard stems. Mince or grate garlic. Drain and rinse half the beans from the box (use the rest as you like). Zest ½ tsp zest from lime, then cut into halves. 3)Heat 1 TBSP olive oil in a large pan over medium heat. Add onion and cook, tossing occasionally, until softened, 5-6 minutes. Season with salt and pepper. Add garlic and beans to pan. Cook, tossing, until fragrant and warmed through, 3-4 minutes. 4)Wrap tortillas in foil and place in oven to warm, about 5 minutes. (TIP: Alternatively, wrap tortillas in a damp paper towel and microwave on high until warm, about 30 seconds.) Toss sweet potatoes, honey, cumin, and juice from one lime half into pan with beans and cook until liquid is mostly evaporated, 2-3 minutes. Season with salt and pepper. 5)Halve, pit, and peel avocado. Cut one half into thin slices. Roughly chop other half and place in a medium bowl along with sour cream, juice from remaining lime half, and lime zest. Mash with a fork until mostly smooth. Season with salt and pepper. 6)Spread avocado crema onto tortillas, then top each with filling, avocado slices, and cilantro. TIP: Break out the hot sauce if you like it spicy.", RecipeIngredientDetails = new List<RecipeIngredientDetail> { new RecipeIngredientDetail{ IngredientName = "Black Beans", QuantityDescription = "6.7 ounces" }, new RecipeIngredientDetail{ IngredientName = "Flour Tortillas", QuantityDescription = "6 units" }, new RecipeIngredientDetail{ IngredientName = "Sweet Potato", QuantityDescription = "2 units" }, new RecipeIngredientDetail{ IngredientName = "Garlic", QuantityDescription = "2 gloves" }, }, ImageUrl = "https://res.cloudinary.com/hellofresh/image/upload/f_auto,fl_lossy,q_80,w_auto:100:1280/v1/hellofresh_s3/image/5abd494fae08b54b610ca122-8bfc3c25.jpg", Author = appUser, AddedOn = DateTime.Now }; recipeRepository.Create(firstRecipe); recipeRepository.Create(secondRecipe); await recipeRepository.SaveChangesAsync(); }
public async Task <Recipe> Create(Recipe toSave) { var response = await _repository.Create(toSave); return(response); }