public async Task <IActionResult> Add(AddRecipeViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = await _userManager.GetUserAsync(User); if (user == null) { ModelState.AddModelError("", "Błąd dodawania przepisu."); return(View(model)); } var recipe = new Recipe() { Preparation = model.Preparation, Name = model.Name, PreparationTime = model.PreparationTime, Ingredients = model.Ingredients, Description = model.Description, User = user }; var result = await _recipeService.CreateAsync(recipe); if (result == false) { ModelState.AddModelError("", "Błąd dodawania przepisu."); return(View(model)); } return(RedirectToAction("List", "Recipe")); }
public async Task <IActionResult> Create([FromBody] CreateRecipe dto) { if (dto == null) { return(BadRequest()); } try { dto.UserId = IdentityHelper.GetUserId(User); } catch (UnauthorizedAccessException) { return(Unauthorized()); } int id = await _recipeService.CreateAsync(dto, _createRecipeValidator); return(StatusCode(201, id)); }
public async Task <ActionResult <RecipeResource> > CreateRecipe([FromBody] RecipeResource model) { var result = await recipeService.CreateAsync(model).ConfigureAwait(false); return(result); }