/// <summary> /// Apaga uma Webpages_Controllers /// </summary> /// <param name="param"></param> /// <returns></returns> private static void DeleteSubController(string token, Int32 id_controller, painel_taxservices_dbContext _dbContext = null) { painel_taxservices_dbContext _db; if (_dbContext == null) { _db = new painel_taxservices_dbContext(); } else { _db = _dbContext; } DbContextTransaction transaction = _db.Database.BeginTransaction(); try { GatewayWebpagesMethods.DeleteControllerMethods(token, id_controller); // Deleta os logs de acesso _db.LogAcesso1.RemoveRange(_db.LogAcesso1.Where(l => l.idController == id_controller)); _db.tbLogAcessoUsuarios.RemoveRange(_db.tbLogAcessoUsuarios.Where(l => l.idController == id_controller)); _db.SaveChanges(); _db.webpages_Controllers.RemoveRange(_db.webpages_Controllers.Where(e => e.id_controller == id_controller)); _db.SaveChanges(); transaction.Commit(); } catch (Exception e) { transaction.Rollback(); if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao apagar controller" : erro); } throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } finally { if (_dbContext == null) { // Fecha conexão _db.Database.Connection.Close(); _db.Dispose(); } } }
/// <summary> /// Adiciona nova Webpages_Controllers /// </summary> /// <param name="param"></param> /// <returns></returns> public static Int32 Add(string token, Models.Object.CadastroController param, painel_taxservices_dbContext _dbContext = null) { painel_taxservices_dbContext _db; if (_dbContext == null) { _db = new painel_taxservices_dbContext(); } else { _db = _dbContext; } try { if (param.Webpagescontrollers.nm_controller == null) { param.Webpagescontrollers.nm_controller = param.Webpagescontrollers.ds_controller; } _db.webpages_Controllers.Add(param.Webpagescontrollers); _db.SaveChanges(); if (param.Methodspadrao) { webpages_Methods put = new webpages_Methods { ds_method = "Atualização", id_controller = param.Webpagescontrollers.id_controller }; webpages_Methods post = new webpages_Methods { ds_method = "Cadastro", id_controller = param.Webpagescontrollers.id_controller }; webpages_Methods get = new webpages_Methods { ds_method = "Leitura", id_controller = param.Webpagescontrollers.id_controller }; webpages_Methods delete = new webpages_Methods { ds_method = "Remoção", id_controller = param.Webpagescontrollers.id_controller }; //webpages_Methods filtroempresa = new webpages_Methods { ds_method = "Filtro Empresa", id_controller = param.Webpagescontrollers.id_controller }; try { GatewayWebpagesMethods.Add(token, put); } catch (Exception e) { throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } try { GatewayWebpagesMethods.Add(token, post); } catch (Exception e) { throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } try { GatewayWebpagesMethods.Add(token, get); } catch (Exception e) { throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } try { GatewayWebpagesMethods.Add(token, delete); } catch (Exception e) { throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } //GatewayWebpagesMethods.Add(token, filtroempresa); } return(param.Webpagescontrollers.id_controller); } catch (Exception e) { if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao salvar controller" : erro); } throw new Exception(e.InnerException == null ? e.Message : e.InnerException.InnerException == null ? e.InnerException.Message : e.InnerException.InnerException.Message); } finally { if (_dbContext == null) { // Fecha conexão _db.Database.Connection.Close(); _db.Dispose(); } } }