public void Update(RecipeWarning recipeWarnings, int id) { try { // Validar datos correctos bool validWarning = Validate(recipeWarnings); if (validWarning) { // Que exista el id bool existWord = dbContext.RecipeWarning.Any(recipeWarnings => recipeWarnings.Id == id); if (existWord) { // actualizar recipeWarnings.Id = id; dbContext.Update(recipeWarnings); dbContext.SaveChanges(); } } } catch (Exception ex) { throw ex; } }
public bool Validate(RecipeWarning recipeWarnings) { try { return(true); } catch (Exception ex) { throw ex; } }
public void Delete(int id) { try { RecipeWarning recipeWarnings = dbContext.RecipeWarning.FirstOrDefault(x => x.Id == id); if (recipeWarnings != null) { dbContext.Remove(recipeWarnings); dbContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public void Create(RecipeWarning recipeWarnings) { try { bool validWarning = Validate(recipeWarnings); if (validWarning) { dbContext.Add(recipeWarnings); dbContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public IActionResult AddWarning([FromBody] RecipeWarning recipeWarning) { try { RecipeWarningCore recipeWarningCore = new RecipeWarningCore(dbContext); //RecipeWarning NewrecipeWarning = new RecipeWarning(); //NewrecipeWarning.IdRecipe = IdRecipe; //NewrecipeWarning.IdWarning = IdWarning; recipeWarningCore.Create(recipeWarning); return(Ok("Warning Added to Recipe Succesfully")); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, ex)); } }