public override void OnException(HttpActionExecutedContext actionExecutedContext) { string exceptionMessage = string.Empty; string StackTrace = string.Empty; if (actionExecutedContext.Exception.InnerException == null) { exceptionMessage = actionExecutedContext.Exception.Message; StackTrace = actionExecutedContext.Exception.StackTrace; } else { exceptionMessage = actionExecutedContext.Exception.Message; StackTrace = actionExecutedContext.Exception.StackTrace; } //We can log this exception message to the file or database. var response = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent("An unhandled exception was thrown by service."), ReasonPhrase = "Internal Server Error.Please Contact your Administrator." }; actionExecutedContext.Response = response; _Logger.ExceptionHandler(actionExecutedContext.Exception, StackTrace, null); }
//public UserRepository(IErrorLogger ErrorLogs) //{ // ErrorLog = ErrorLogs; //} /// <summary> /// GetListUsers this method is used to get the users data /// </summary> /// <returns></returns> public IEnumerable <User> GetListUsers() { List <User> LstUser = new List <User>(); User user = null; NpgsqlDataReader rdr; try { using (NpgsqlConnection con = new NpgsqlConnection(connectionString)) { NpgsqlCommand cmd = new NpgsqlCommand("SELECT userid, username, password, email, createddate, lastlogindate FROM public.users;", con); if (con.State == ConnectionState.Closed) { con.Open(); } rdr = cmd.ExecuteReader(); while (rdr.Read()) { user = new User(); user.UserId = (int)rdr["userid"]; user.Username = rdr["username"].ToString(); user.Email = rdr["email"].ToString(); //user.CreatedDate = (DateTime)rdr["createddate"].ToString()); LstUser.Add(user); } con.Close(); } } catch (Exception ex) { ErrorLog.ExceptionHandler(ex, "GetListUsers", "User Module"); } finally { user = null; rdr = null; } return(LstUser); }
/// <summary> /// GetListRoles this method is used to fetch the list of roles from the database /// </summary> /// <returns></returns> public IEnumerable <Role> GetListRoles() { List <Role> LstRoles = new List <Role>(); Role role = null; NpgsqlDataReader rdr; try { using (NpgsqlConnection con = new NpgsqlConnection(connectionString)) { NpgsqlCommand cmd = new NpgsqlCommand("SELECT roleid, rolename FROM public.roles;", con); if (con.State == ConnectionState.Closed) { con.Open(); } rdr = cmd.ExecuteReader(); while (rdr.Read()) { role = new Role(); role.RoleId = (int)rdr["roleid"]; role.RoleName = rdr["rolename"].ToString(); LstRoles.Add(role); } con.Close(); } } catch (Exception ex) { ErrorLog.ExceptionHandler(ex, "GetListRoles", "Role Module"); } finally { role = null; rdr = null; } return(LstRoles); }