public ActionResult ExcluirIngredienteLocal(string id_ing = "0") { try { long ing_id = 0; if (id_ing.Trim() != "") { ing_id = Convert.ToInt64(id_ing); } if (ing_id != 0) { local_ingred_tables local_ingred_tables = new local_ingred_tables(); exist_ingredients exist_ingredients = new exist_ingredients(); Local_Ingred_User Local_Ingred_User = new Local_Ingred_User(); local_ingred_tables.GetConnection().CriaTransaction(); exist_ingredients.SetConnection(local_ingred_tables.GetConnection()); Local_Ingred_User.SetConnection(local_ingred_tables.GetConnection()); Local_Ingred_User.Excluir(ing_id); local_ingred_tables.ExcluirPorIngrediente(ing_id); exist_ingredients.Excluir(ing_id); // excluir do vinculo de tabelas local_ingred_tables.GetConnection().TransCommit(); } return(Json(new { status = "success" })); } catch (Exception ex) { return(Json(new { status = "error" })); } }
public ActionResult SalvaIngredienteLocal(string name_ingrediente, long ingred_id, string model) { try { // incluir no cadastro de ingrediente // salvar valores para todas as tabelas string[] arrValues = new string[0]; arrValues = model.Split(','); var usuario = getUser().user_id; var lang = GetLangId(this, Session["lang_code"].ToString()); exist_base_tables exist_base_tables = new exist_base_tables(); exist_ingredients exist_ingredients = new exist_ingredients(); local_ingred_tables local_ingred_tables = new local_ingred_tables(); Local_Ingred_User Local_Ingred_User = new Local_Ingred_User(); var tabelas = exist_base_tables.Consultar(usuario, lang); exist_ingredients.GetConnection().CriaTransaction(); local_ingred_tables.SetConnection(exist_ingredients.GetConnection()); Local_Ingred_User.SetConnection(exist_ingredients.GetConnection()); var retorno = exist_ingredients.Incluir(name_ingrediente); long ingrediente = Convert.ToInt64(retorno); DataTable dt_nutrs = (DataTable)TempData["dt_nutrients"]; TempData.Keep("dt_nutrients"); Local_Ingred_AlterUserDto local_ingred = new Local_Ingred_AlterUserDto(); local_ingred.user_id = usuario; local_ingred.ingred_id = ingrediente; Local_Ingred_User.Incluir(ingrediente, usuario); foreach (Exist_Base_TablesDto tabela in tabelas) { local_ingred.table_id = tabela.table_id; var index = -1; for (int i = 0; i < arrValues.Length - 1; i++) { var nutr_id = Convert.ToInt64(dt_nutrs.Rows[i]["nutr_id"]); local_ingred.nutr_id = nutr_id; local_ingred.nutr_value = Convert.ToDecimal(arrValues[i]); local_ingred_tables.Inserir(local_ingred); } } exist_ingredients.GetConnection().TransCommit(); return(Json(new { status = "success" })); } catch (Exception ex) { return(Json(new { status = "error" })); } }