private void SeedRepo() { for (int i = 0; i < 100; i++) { var item = new Recipe ( i, $"Recipe{i}", new List <RecipeStep> { new RecipeStep ( 0, "First Recipe Step", "This is a description", "This is a URL" ), new RecipeStep ( 1, "Second Recipe Step", "This is a description", "This is a URL" ) }, 0); _repository.Add(item); } }
public void AddRecipe(Recipe Recipe) { //Recipe.Note = "0"; Recipe.isDelete = false; _RecipeRepository.Add(Recipe); _unitOfWork.Commit(); }
private void CreateNewRecipeInCategory(int categoryId) { Console.Write("Введите название рецепта: "); var name = Console.ReadLine(); Console.Write("Введите описание рецепта: "); var description = Console.ReadLine(); ShowIngridients(); Console.WriteLine("Введите номера ингридиентов рецепта через запятую: "); var ingredientNumbers = Console.ReadLine().Split(","); var ingredients = ingredientNumbers .Where(i => int.TryParse(i, out int intId)) .Select(i => _ingredientRepository.SingleOrDefault(n => n.Id == int.Parse(i))) .Where(i => i != null) .ToList(); Console.WriteLine("Введите шаги приготовления в рецепте через точку с запятой (;): "); var steps = Console.ReadLine().Split(";"); var newRecipe = new Recipe(-1, categoryId, name, description, ingredients, steps.ToList()); _recipeRepository.Add(newRecipe); _unitOfWork.Save(); Console.WriteLine("Новый рецепт добавлен!"); }
public IActionResult CreateRecipe(RecipeViewModel model) { if (ModelState.IsValid) { string uniqueFileName = ProcessUploadedFile(model, "images"); Recipe newRecipe = new Recipe { Name = model.Name, Description = model.Description, PhotoPatch = uniqueFileName, AuthorId = _signInManager.UserManager.GetUserId(User), Ingridients = model.Ingridients.SerializeListToString(), Tags = model.Tags.SerializeListToString(), Time = model.Time, Hint = model.Hint, AddedTime = DateTime.Today, DifficultLevel = model.DifficultLevel }; _recipeRepository.Add(newRecipe); newRecipe.EncryptedId = _protector.Protect(newRecipe.Id.ToString()); return(RedirectToAction("details", new { id = newRecipe.EncryptedId })); } return(View()); }
public RedirectToRouteResult Create(Recipe r) { if (r.Name != null) { recipeRepository.Add(r); recipeRepository.Save(); } return(RedirectToAction("Index", "Recipe")); }
public async Task <Recipe> Create(NewRecipeDto newItem) { if (newItem == null) { throw new ArgumentNullException(); } var recipe = _mapper.Map <Recipe>(newItem); await _repository.Add(recipe); //var recipeDto = _mapper.Map<RecipeDto>(newItem); return(recipe); }
//[Authorize] public ActionResult Create([FromBody] RecipeCreateRequest request) { if (!ModelState.IsValid) { return(Ok(ModelState)); } var response = new BaseResponse <Guid>(); if (recipeRepo.Any(x => x.Title == request.Title)) { response.SetMessage("Bu yemek tarifi kayıtlı"); return(Ok(response)); } var item = new Recipe { Title = request.Title, Details = request.Details, UserID = CurrentUserID, Slug = request.Title.ToUrlSlug(), ServiceCount = request.ServiceCount, Calories = request.Calories, PrepareTime = request.PrepareTime, CookingTime = request.CookingTime, VideoLink = request.VideoLink, Ingredients = request.Ingredients.Select(y => new RecipeIngredient { Title = y.Title }).ToList(), Steps = request.Steps.Select(y => new Entity.Definition.Step { Title = y.Title }).ToList(), Images = request.Images.Select(y => new RecipeImage { Image = y.image }).ToList(), RecipeCategories = request.Categories.Select(y => new RecipeCategory { CategoryID = y.CategoryID }).ToList() }; recipeRepo.Add(item); response.Data = item.Id; response.Message = "Kayıt başarıyla eklenmiştir."; return(Ok(response)); }
public ViewResult AddRecipe(Recipe recipe, int recipePage = 1) { repository.Add(recipe); return(View("List", new RecipeListViewModel { Recipes = repository.Recipes.OrderBy(r => r.RecipeId).Skip((recipePage - 1) * PageSize).Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = recipePage, RecipesPerPage = PageSize, TotalRecipes = repository.Recipes.Count() } })); }
public async Task <IActionResult> Create(Recipe recipe, int id) { var dietType = _db.GetDietType(id); ViewBag.DietType_Id = dietType.Id; ViewBag.DietType_Name = dietType.Name; recipe.DietId = id; recipe.Id = 0; await _db.Add(recipe); var recipeList = await _db.GetAllRecipies(id); return(View("Index", recipeList)); }
public ActionResult <Recipe> PostRecipe(RecipeDTO recipe) { Recipe recipeToCreate = new Recipe() { Name = recipe.Name, Chef = recipe.Chef }; foreach (var i in recipe.Ingredients) { recipeToCreate.AddIngredient(new Ingredient(i.Name, i.Amount, i.Unit)); } _recipeRepository.Add(recipeToCreate); _recipeRepository.SaveChanges(); return(CreatedAtAction(nameof(GetRecipe), new { id = recipeToCreate.Id }, recipeToCreate)); }
public ActionResult AddRecipe([FromBody] Recipe recipe) { try { if (recipe == null || !ModelState.IsValid) { return(StatusCode(ExceptionsCodes.BadRequest.statusCode, ExceptionsCodes.BadRequest.message)); } _RecipeRepository.Add(recipe); return(StatusCode(ExceptionsCodes.Succeccful.statusCode, ExceptionsCodes.Succeccful.message)); } catch (ExceptionsCodes ex) { return(StatusCode(ex.statusCode, ex.message)); } }
public async Task <IActionResult> Recipe(RecipeViewModel model) { if (model.Ingredients == null) { ModelState.AddModelError("Ingredients", "Należy dodać chociażby jeden składnik"); } if (!ModelState.IsValid) { if (ModelState["TypeId"].Errors.Count != 0) { ModelState.Remove("TypeId"); ModelState.SetModelValue("TypeId", new ValueProviderResult("Należy wybrać typ przepisu", CultureInfo.InvariantCulture)); ModelState.AddModelError("TypeId", "Należy wybrać typ przepisu"); } model.Types = await typeRepository.Types(); return(View("Recipe", model)); } if (model.Image != null) { if (model.Image.Length > 0) { using (var stream = new MemoryStream()) { await model.Image.CopyToAsync(stream); model.Recipe.Img = stream.ToArray(); } } } IEnumerable <Product> productsToIngredients = await productRepository.FindAllAsync(p => model.Ingredients.Any(i => i.Id == p.Id)); model.Recipe.Ingredients = new List <Ingredient>(); foreach (var product in productsToIngredients) { model.Recipe.Ingredients.Add(new Ingredient { Product = product, Quantity = model.Ingredients.Where(i => i.Id == product.Id).First().Quantity }); } model.Recipe.Type = await typeRepository.FindAsync(t => t.Id == model.TypeId); recipeRepository.Add(model.Recipe); return(RedirectToAction("Recipe")); }
public IActionResult Create(RecipeViewModel recipeViewModel) { if (ModelState.IsValid) { Recipe recipe = new Recipe { Name = recipeViewModel.Name, PictureId = recipeViewModel.PictureId, Description = recipeViewModel.Description, Price = recipeViewModel.Price, CategoryId = recipeViewModel.RecipeCategory.CategoryId }; _recipeRepository.Add(recipe); return(RedirectToAction("Index")); } return(View(recipeViewModel)); }
public ActionResult Post([FromBody] Recipe recipe) { if (ModelState.IsValid) { if (recipe.Id == 0) { _repository.Add(recipe); return(Ok()); } else { return(BadRequest("Use PUT for changing an existing recipe")); } } else { return(BadRequest("Invalid recipe")); } }
public IActionResult OnPost(Recipe recipe) { if (ModelState.IsValid) { if (Photo != null) { recipe.PhotoPath = ProcessUploadedFile(); } if (Recipe.Id > 0) { Recipe = recipeRepository.Update(recipe); } else { Recipe = recipeRepository.Add(recipe); } return(RedirectToPage("Index")); } return(Page()); }
public async Task <TotalRecipeModel> Add(UpsertRecipeModel model) { model.IdUser = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "IdUser").Value); var recipe = _mapper.Map <Persistance.Models.Recipes>(model); model.Ingredients = model.Ingredients.Distinct().ToList(); foreach (var ingredient in model.Ingredients) { var ing = await _ingredients.GetByName(ingredient); if (ing == null) { recipe.Ingredients.Add(new RecipesIngredients(recipe, new Ingredients(ingredient))); } else { recipe.Ingredients.Add(new RecipesIngredients(recipe, ing)); } } var fil = await _filters.GetByName(model.Filter); if (fil == null) { recipe.Filters.Add(new RecipesFilters(recipe, new Filters(model.Filter))); } else { recipe.Filters.Add(new RecipesFilters(recipe, fil)); } //recipe.Ingredients = recipe.RecipesIngredients.Select(x => x.Ingredient).ToList(); //recipe.Filters = recipe.RecipesFilters.Select(x => x.Filter).ToList(); await _repository.Add(recipe); await _repository.SaveChanges(); return(_mapper.Map <TotalRecipeModel>(recipe)); }
public async Task <IActionResult> Create([FromBody] CreateRecipeRequest request) { /* var recipe = new Recipe * { * Title = request.Title, * Summary = request.Summary, * Directions = request.Directions, * Ingredients = request.Ingredients, * NutritionInfo = request.NutritionInfo * }; */ var recipe = _mapper.Map <Recipe>(request); repository.Add(recipe); if (await repository.SaveAll()) { return(Ok()); } throw new Exception(GlobalConstants.ERROR_SAVING_CHANGES); }
public int AddRecipe(AddRecipeViewModel addRecipe) { var selecteditem = GetSelectCategories(); var item = new SelectItemViewModel(); Recipe recipe = new Recipe { RecipeName = addRecipe.RecipeName, RecipeImage = addRecipe.RecipeImage, RecipeDescription = addRecipe.RecipeDescription.Replace("../..", ""), CreatedAt = DateTime.Now, ModefiedAt = DateTime.Now, CookingTime = addRecipe.CookingTime, RecipeCategoryId = addRecipe.RecipeCategoryId, RecipeCategory = addRecipe.RecipeCategory, }; _recipeRepository.Add(recipe); _recipeRepository.SaveChanges(); return(recipe.Id); }
public Task <Unit> Handle(AddRecipeUseCase request, CancellationToken cancellationToken) { if (_repo.Get(r => r.Name.ToLower() == request.Name.ToLower()).Any()) { throw new EntityAlreadyExistsException($"{request.Name} is already in use."); } _repo.Add(new Domain.Entities.Recipe { Name = request.Name, Description = request.Description, Keyword = request.Keyword }); _bus.Publish(new RecipeCreatedEvent() { DateCreated = DateTime.Now, RecipeName = request.Name, Email = "*****@*****.**", Username = "******" }); return(Unit.Task); }
public ViewResult AddRecipe(Recipe recipe, int recipePage = 1) { repository.Add(recipe); return(View("Index", repository.Recipes)); }
public void Add(Recipe recipe) { _repository.Add(recipe); }
public IHttpActionResult Add([FromBody] Recipe recipe) { repository.Add(recipe); return(Ok()); }
public void Insert(Recipe entity) { _recipeRepository.Add(entity); }
public Recipe Add(Recipe recipe) { _recipeRepo.Add(recipe); return(recipe); }
public int Add(Recipe recipe) { return(recipeRepo.Add(recipe)); }
public void AddRecipe(Recipes recipe) { _recipeRepository.Add(recipe); _recipeRepository.Save(); }
public async Task <ICommandResult> Handle(AddRecipeCommand command) { var dataSource = await _repository.Add(command); return(new GenericResult(dataSource)); }