public async Task <ActionResult <AspNetUserRecipe> > GetAspNetUserRecipe(long idRecipe) { if (!HttpContext.User.Identity.IsAuthenticated) { return(null); } var idUser = GetUserId(); var aspNetUserRecipe = await _context.AspNetUserRecipes.Where(ur => ur.IdRecipe == idRecipe && ur.IdUser == idUser).FirstOrDefaultAsync(); if (aspNetUserRecipe == null) { var newUserRecipe = new AspNetUserRecipe() { IdRecipe = idRecipe, IdUser = idUser, IsFavorite = false }; _context.AspNetUserRecipes.Add(newUserRecipe); await _context.SaveChangesAsync(); aspNetUserRecipe = await _context.AspNetUserRecipes.Where(ur => ur.IdRecipe == idRecipe && ur.IdUser == idUser).FirstOrDefaultAsync(); } return(Ok(aspNetUserRecipe)); }
public async Task <IActionResult> PutAspNetUserRecipe(long id, AspNetUserRecipe aspNetUserRecipe) { if (id != aspNetUserRecipe.Id) { return(BadRequest()); } _context.Entry(aspNetUserRecipe).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AspNetUserRecipeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task UpdateUserRecipe(long idUserRecipe, AspNetUserRecipe newUserRecipe) { var response = await httpClient.PutAsJsonAsync($"userrecipes/{idUserRecipe}", newUserRecipe); response.EnsureSuccessStatusCode(); }