// PUT /webpages_RoleLevels/token/ public HttpResponseMessage Put(string token, [FromBody] webpages_RoleLevels param) { // Abre nova conexão using (painel_taxservices_dbContext _db = new painel_taxservices_dbContext()) { tbLogAcessoUsuario log = new tbLogAcessoUsuario(); try { HttpResponseMessage retorno = new HttpResponseMessage(); log = Bibliotecas.LogAcaoUsuario.New(token, JsonConvert.SerializeObject(param), "Put", _db); if (Permissoes.Autenticado(token, _db)) { GatewayWebpagesRoleLevels.Update(token, param, _db); log.codResposta = (int)HttpStatusCode.OK; Bibliotecas.LogAcaoUsuario.Save(log, _db); return(Request.CreateResponse(HttpStatusCode.OK)); } else { log.codResposta = (int)HttpStatusCode.Unauthorized; Bibliotecas.LogAcaoUsuario.Save(log, _db); return(Request.CreateResponse(HttpStatusCode.Unauthorized)); } } catch (Exception e) { log.codResposta = (int)HttpStatusCode.InternalServerError; log.msgErro = e.Message; Bibliotecas.LogAcaoUsuario.Save(log); throw new HttpResponseException(HttpStatusCode.InternalServerError); } } }
/// <summary> /// Altera webpages_RoleLevels /// </summary> /// <param name="param"></param> /// <returns></returns> public static void Update(string token, webpages_RoleLevels param, painel_taxservices_dbContext _dbContext = null) { painel_taxservices_dbContext _db; if (_dbContext == null) { _db = new painel_taxservices_dbContext(); } else { _db = _dbContext; } try { webpages_RoleLevels value = _db.webpages_RoleLevels .Where(e => e.LevelId.Equals(param.LevelId)) .First <webpages_RoleLevels>(); // OBSERVAÇÂO: VERIFICAR SE EXISTE ALTERAÇÃO NO PARAMETROS if (param.LevelId != value.LevelId) { value.LevelId = param.LevelId; } if (param.LevelName != null && param.LevelName != value.LevelName) { value.LevelName = param.LevelName; } _db.SaveChanges(); } catch (Exception e) { if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao alterar role level" : 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_RoleLevels /// </summary> /// <param name="param"></param> /// <returns></returns> public static Int32 Add(string token, webpages_RoleLevels param, painel_taxservices_dbContext _dbContext = null) { painel_taxservices_dbContext _db; if (_dbContext == null) { _db = new painel_taxservices_dbContext(); } else { _db = _dbContext; } try { _db.webpages_RoleLevels.Add(param); _db.SaveChanges(); return(param.LevelId); } catch (Exception e) { if (e is DbEntityValidationException) { string erro = MensagemErro.getMensagemErro((DbEntityValidationException)e); throw new Exception(erro.Equals("") ? "Falha ao salvar role levels" : 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(); } } }