public async Task <IHttpActionResult> Post(RecipeCreateBindingModel recipe) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var recipeEntity = new Recipe { Description = recipe.Description, ImageUrl = recipe.ImageUrl, AmountOfTime = TimeSpan.Parse(recipe.AmountOfTime), Servings = recipe.Servings, Name = recipe.Name, Steps = recipe.Steps, Votes = recipe.Votes, RecipeIngredientDetails = recipe.RecipeIngredientDetails.Select(x => new RecipeIngredientDetail { IngredientName = x.IngredientName, QuantityDescription = x.QuantityDescription }).ToList(), AuthorId = Thread.CurrentPrincipal.Identity.GetUserId(), AddedOn = DateTime.Now }; this.recipeRepository.Create(recipeEntity); await this.recipeRepository.SaveChangesAsync(); return(this.Ok()); }
private RecipeCreateBindingModel DummyDataBindingRecipe() { var recipe = new RecipeCreateBindingModel { Name = "Musaka", Description = "Musaka Description", Portions = 4, Price = 4.99M, RecipeInstructions = "Musaka InstructionsMusaka InstructionsMusaka InstructionsMusaka Instructions", Ingredients = new List <RecipeIngredientBindingModel> { new RecipeIngredientBindingModel(), new RecipeIngredientBindingModel(), }, }; return(recipe); }