internal static void UpdateApiLogEntry(ApiLogEntry logEntry, IRestResponse <dynamic> restResponse) { using (TeamDbContext dbContext = new TeamDbContext()) { ApiLogEntry dbEntry = dbContext.ApiLogEntries.Find(logEntry.ApiLogEntryId); dbEntry.ResponseHeaders = LoggerService.SerializeHeaders(restResponse.Headers); dbEntry.ResponseContentType = restResponse.ContentType; dbEntry.ResponseContentBody = restResponse.Content; dbEntry.ResponseStatusCode = (int)restResponse.StatusCode; dbEntry.ResponseTimestamp = DateTime.Now; dbContext.SaveChanges(); } }
internal static string SettingGet(string keyName) { keyName = keyName.ToUpper(CultureInfo.InvariantCulture); using (TeamDbContext dbContext = new TeamDbContext()) { Setting setting = dbContext.Settings.FirstOrDefault(e => e.Key == keyName && !e.Deleted); if (setting != null) { return(setting.Value); } } return(null); }
public static async Task <ResponseBase <DashboardWidget> > EditWidgetAsync(TeamHttpContext teamHttpContext, int editwidgetId) { List <UserDashboard> objEditWidget = new List <UserDashboard>(); using (TeamDbContext dbContext = new TeamDbContext()) { objEditWidget = dbContext.UserDashboards.Where(x => x.Id == editwidgetId).ToList(); } if (objEditWidget.Count != 0) { foreach (var item in objEditWidget) { DashboardWidget objWidgetEdit = new DashboardWidget { DashboardWidgetName = item.DashboardWidgetName, WidgetId = item.Id, DashboardChartType = item.DashboardChartType, DashboardUserPermission = item.DashboardUserPermission, DashboardEmailFormat = item.DashboardEmailFormat, WidgetConnectionString = item.WidgetConnectionString, WidgetSchedulerType = item.WidgetSchedulerType, WidgetSchedulerEmailIDs = item.WidgetSchedulerEmailIDs, WidgetQuery = item.WidgetQuery, Level1ConnectionString = item.Level1ConnectionString, Level1SchedulerType = item.Level1SchedulerType, L1SchedulerEmailIDs = item.L1SchedulerEmailIDs, DashbaordQueryL1 = item.DashbaordQueryL1, Level2ConnectionString = item.Level2ConnectionString, Level2SchedulerType = item.Level2SchedulerType, L2SchedulerEmailIDs = item.L2SchedulerEmailIDs, DashbaordQueryL2 = item.DashbaordQueryL2, Level3ConnectionString = item.Level3ConnectionString, Level3SchedulerType = item.Level3SchedulerType, L3SchedulerEmailIDs = item.L3SchedulerEmailIDs, DashbaordQueryL3 = item.DashbaordQueryL3, Level4ConnectionString = item.Level4ConnectionString, Level4SchedulerType = item.Level4SchedulerType, L4SchedulerEmailIDs = item.L4SchedulerEmailIDs, DashbaordQueryL4 = item.DashbaordQueryL4, WidgetSendEmail = item.WidgetSendEmail }; return(GetTypedResponse(teamHttpContext, objWidgetEdit)); } } return(null); }
internal static async Task <List <AddEditNewUser> > GetUserAsync(TeamHttpContext httpContext, int userid) { string connString = Utility.GetConnectionString("PgAdmin4ConnectionString"); List <AddEditNewUser> returnValue = new List <AddEditNewUser>(); PostgresService postgresService = new PostgresService(); List <User> objUser = new List <User>(); using (TeamDbContext dbContext = new TeamDbContext()) { if (userid != -1) { objUser = dbContext.Users.Where(x => x.Deleted == false && x.Id == userid).ToList(); } else { objUser = dbContext.Users.Where(x => x.Deleted == false && x.UserType != UserType.Admin).ToList(); } } if (objUser.Count != 0) { foreach (var item in objUser) { var userstatus = (item.Status == UserStatus.Active) ? true : false; AddEditNewUser newItem = new AddEditNewUser { UserId = item.UserId, Password = "******", UserEmail = item.Email, TableId = item.Id, IsActive = userstatus, IsAddPermission = item.IsAdd, IsEditPermission = item.IsEdit, IsDeletePermission = item.IsDelete }; returnValue.Add(newItem); } return(returnValue); } else { return(null); } }
internal static async Task <ResponseBase> editReport(TeamHttpContext httpContext, ReportConfigAddEdit report) { try { List <ReportConfig> objReportConfig = new List <ReportConfig>(); using (TeamDbContext dbContext = new TeamDbContext()) { if (dbContext.ReportConfigs.AsNoTracking().FirstOrDefault(e => e.Id == report.ReportId) != null) { objReportConfig = dbContext.ReportConfigs.Where(x => x.Id == report.ReportId).ToList(); } } if (objReportConfig.Count != 0) { EditReport(new ReportConfig { Id = report.ReportId, ReportReqUserId = httpContext.ContextUserId, //ReportReqUserId = "Admin", ReportName = report.ReportName, ReportConnectionString = report.ReportConnectionString, ReportQuery = report.ReportQuery, ReportEmail = report.ReportEmail, ReportFileFormat = report.ReportFormat, CreatedBy = objReportConfig[0].CreatedBy, CreatedOn = objReportConfig[0].CreatedOn, ModifiedBy = httpContext.ContextUserId, //ModifiedBy = "Admin", ModifiedOn = DateTime.Now, ReportModifiedOn = DateTime.Now, Deleted = !(report.IsActive), ReportDeliveryOption = report.ReportDeliveryMode, ReportSMSPhNo = report.ReportSMSPhoneNumber, ReportDefaultSMSMsg = report.ReportDefaultSMSMSG, ReportSchedulerName = report.ReportSchedulerName }); return(GetResponse(httpContext, HttpStatusCode.OK, "Available")); } return(null); } catch (Exception ex) { return(GetResponse(httpContext, HttpStatusCode.BadRequest, ex.Message.ToString())); } }
public static async Task NotifyErrorsAsync(TeamHttpContext teamContext) { using (TeamDbContext dbContext = new TeamDbContext()) { List <AppLogEntry> errors = dbContext.AppLogEntries.Where(e => e.Level == "ERROR" && !e.AdminNotified).Take(25).ToList(); HashSet <string> sentErrors = new HashSet <string>(); StringBuilder sb = new StringBuilder(); foreach (AppLogEntry item in errors) { // don't notify for the same error string messageKey = $"{item.User}:{item.ExceptionMessage}"; // skip certain errors // check that we have not notified this user/error combination. if (!Utility.IsDevelopment && !item.ExceptionMessage.Contains("The timeout period elapsed prior to completion of the", StringComparison.InvariantCulture) && !item.ExceptionMessage.Contains("Unauthorized, Please login to continue", StringComparison.InvariantCulture) && !sentErrors.Contains(messageKey)) { sb.Append(Utility.GetFormattedLabelValue("Id", item.Id)); sb.Append(Utility.GetFormattedLabelValue("User", item.User)); sb.Append(Utility.GetFormattedLabelValue("Thread", item.RequestId)); sb.Append(Utility.GetFormattedLabelValue("Time", item.Date.ToString(CultureInfo.InvariantCulture))); sb.Append(Utility.GetFormattedLabelValue("Location", item.Message)); sb.Append(Utility.GetFormattedLabelValue("Message", item.ExceptionMessage)); sb.Append("<br/><br/>"); sentErrors.Add(messageKey); } item.AdminNotified = true; } string body = sb.ToString(); if (body.Length != 0) { string adminMailAddress = Utility.GetConfigValue("notifications:sysAdminEmailAddress"); await EmailService.SendAsync(adminMailAddress, "IA:Application Errors", body, string.Empty).ConfigureAwait(false); } if (errors.Count > 0) { await dbContext.SaveChangesAsync().ConfigureAwait(false); } } }
internal static async Task <List <LoadDashboard> > GetAllWidgetAsync(TeamHttpContext httpContext) { string userid = httpContext.ContextUserId; List <LoadDashboard> returnValue = new List <LoadDashboard>(); PostgresService postgresService = new PostgresService(); List <UserDashboard> objUserDashboard = new List <UserDashboard>(); using (TeamDbContext dbContext = new TeamDbContext()) { //objUserDashboard = dbContext.UserDashboards.Where(x => x.DashboardUserId == userid && x.Deleted == false).ToList(); //user specific //objUserDashboard = dbContext.UserDashboards.Where(x => x.Deleted == false).ToList(); // For all users objUserDashboard = dbContext.UserDashboards.Where(x => x.Deleted == false && x.DashboardUserPermission.Contains(httpContext.ContextUserId)).ToList(); // For permitted users } if (objUserDashboard.Count != 0) { foreach (var item in objUserDashboard) { List <WidgetRead> objWidgetRead = new List <WidgetRead>(); string connString = Utility.GetConnectionString(item.WidgetConnectionString); using (NpgsqlDataReader sqlData = postgresService.ExecuteSqlReturnReader(connString, item.WidgetQuery)) { while (sqlData.Read()) { objWidgetRead.Add(new WidgetRead { Name = sqlData.GetBlankStringIfNull("name"), Count = sqlData.GetInt32("count") }); } } LoadDashboard newItem = new LoadDashboard { DashboardWidgetName = item.DashboardWidgetName, DashboardWidgetId = item.Id, DashboardWidgetType = item.DashboardChartType, DashbaordWidgetData = objWidgetRead.ToArray() }; returnValue.Add(newItem); } } return(returnValue); }
internal async static Task <ResponseBase> EditUser(TeamHttpContext httpContext, AddEditNewUser details) { try { List <User> objUser = new List <User>(); using (TeamDbContext dbContext = new TeamDbContext()) { if (dbContext.Users.AsNoTracking().FirstOrDefault(e => e.Id == details.TableId) != null) { objUser = dbContext.Users.Where(x => x.Id == details.TableId).ToList(); } } var userstatus = (details.IsActive) ? 1 : 2; if (objUser.Count != 0) { EditUserDatabase(new User { Id = details.TableId, UserId = details.UserId.ToUpper(CultureInfo.InvariantCulture), Password = (details.Password.Contains("*******")) ? objUser[0].Password : Utility.GetMd5Hash(details.Password), Email = details.UserEmail, ModifiedBy = httpContext.ContextUserId, //ModifiedBy = "Admin", ModifiedOn = DateTime.Now, UserType = UserType.Client, CreatedBy = objUser[0].CreatedBy, CreatedOn = objUser[0].CreatedOn, Status = (UserStatus)userstatus, IsAdd = details.IsAddPermission, IsEdit = details.IsEditPermission, IsDelete = details.IsDeletePermission, }); return(GetResponse(httpContext, HttpStatusCode.OK, "Available")); } return(null); } catch (Exception ex) { return(GetResponse(httpContext, HttpStatusCode.BadRequest, ex.Message.ToString())); } }
private async static Task <User> ValidatePassword(TeamHttpContext teamHttpContext, LoginModel loginModel) { loginModel.UserId = loginModel.UserId.ToUpper(CultureInfo.InvariantCulture); using (TeamDbContext dbContext = new TeamDbContext()) { User user = dbContext.Users.FirstOrDefault(e => e.UserId == loginModel.UserId && !e.Deleted); if (user?.Status == UserStatus.Active) { string encPassword = Utility.GetMd5Hash(loginModel.Password); if (user.Password == encPassword) { return(user); } } return(null); } }
public static async Task <ResponseBase <List <AddEditNewUser> > > AddEditNewUser(TeamHttpContext teamHttpContext, List <AddEditNewUser> details) { if (teamHttpContext == null) { throw new ArgumentNullException(nameof(teamHttpContext)); } List <AddEditNewUser> AllEditedUser = new List <AddEditNewUser>(); for (int i = 0; i <= details.Count - 1; i++) { if (details[i].TableId == -1) { ResponseBase user = await AddUser(teamHttpContext, details[i]).ConfigureAwait(false); if (user.Code == HttpStatusCode.OK) { var USERID = -1; using (TeamDbContext dbContext = new TeamDbContext()) { USERID = dbContext.Users.OrderByDescending(x => x.Id).First().Id; } List <AddEditNewUser> NewUser = await GetUserAsync(teamHttpContext, USERID).ConfigureAwait(false); return(GetTypedResponse(teamHttpContext, NewUser)); } } else { ResponseBase user = await EditUser(teamHttpContext, details[i]).ConfigureAwait(false); if (user.Code == HttpStatusCode.OK) { int.TryParse(details[i].TableId.ToString(), out int userid); List <AddEditNewUser> EditUser = await GetUserAsync(teamHttpContext, userid).ConfigureAwait(false); AllEditedUser.Add(EditUser[0]); } } } return(GetTypedResponse(teamHttpContext, AllEditedUser)); }
internal static async Task <ResponseBase> DeleteWidgetAsync(TeamHttpContext teamHttpContext, int widgetId) { try { using (TeamDbContext dbContext = new TeamDbContext()) { var widget = await dbContext.UserDashboards.FindAsync(widgetId).ConfigureAwait(false); if (widget != null) { dbContext.UserDashboards.Remove(widget); await dbContext.SaveChangesAsync().ConfigureAwait(false); } } return(GetResponse(teamHttpContext)); } catch (Exception ex) { return(GetResponse(teamHttpContext, HttpStatusCode.BadRequest, ex.Message.ToString())); } }
private User ValidateSession(AuthorizationFilterContext context, LoginResponseModel loginResponseModel) { User user = null; string sessionIdFromCache = CacheService.GetSessionId(context.HttpContext, loginResponseModel.SessionId); // TODO: Handle sessions between server restarts and app-updates if (!string.IsNullOrWhiteSpace(sessionIdFromCache)) { user = CacheService.GetUserAsync(context.HttpContext, loginResponseModel.UserId).Result; } if (user == null) { using (TeamDbContext dbContext = new TeamDbContext()) { UserSession userSession = dbContext.UserSessions.FirstOrDefault(e => e.SessionId == loginResponseModel.SessionId && e.Active); if (userSession == null) { context.Result = new UnauthorizedResult(); return(null); } user = dbContext.Users.FirstOrDefault(e => e.UserId == loginResponseModel.UserId.ToUpper(CultureInfo.InvariantCulture)); if (user == null) { context.Result = new UnauthorizedResult(); return(null); } //AuthService.PopulateUserClientsAsync(dbContext, user); // save user to session CacheService.StoreUserAsync(context.HttpContext, user); } } return(user); }
internal static void SettingSet(string keyName, string value) { keyName = keyName.ToUpper(CultureInfo.InvariantCulture); using (TeamDbContext dbContext = new TeamDbContext()) { Setting setting = dbContext.Settings.FirstOrDefault(e => e.Key == keyName && !e.Deleted); if (setting == null) { dbContext.Settings.Add(new Setting { Key = keyName, Value = value }); } else { setting.Value = value; } dbContext.SaveChanges(); } }
internal static async Task <ResponseBase> UpdateScheduler(TeamHttpContext httpContext, SchedulerAddUpdate details) { try { List <Scheduler> objScheduler = new List <Scheduler>(); using (TeamDbContext dbContext = new TeamDbContext()) { if (dbContext.Schedulers.AsNoTracking().FirstOrDefault(e => e.Id == details.SchedulerId) != null) { objScheduler = dbContext.Schedulers.Where(x => x.Id == details.SchedulerId).ToList(); } } if (objScheduler.Count != 0) { UpdateSchedulerDatabase(new Scheduler { Id = details.SchedulerId, SchedulerName = details.SchedulerName, SchedulerWorkStartTime = details.SchedulerWorkStartTime, SchedulerWorkEndTime = details.SchedulerWorkEndTime, SchedulerFrequecy = details.SchedulerSendFrequency, SchedulerSendTime = details.SchedulerSendTime, SchedulerFrequecyValue = details.SchedulerSendFrequencyValue, CreatedBy = objScheduler[0].CreatedBy, CreatedOn = objScheduler[0].CreatedOn, ModifiedBy = httpContext.ContextUserId, ModifiedOn = DateTime.Now }); return(GetResponse(httpContext, HttpStatusCode.OK, "Available")); } return(null); } catch (Exception ex) { return(GetResponse(httpContext, HttpStatusCode.BadRequest, ex.Message.ToString())); } }
public static async Task <ResponseBase> LogoutAsync(TeamHttpContext teamHttpContext, string LogoutuserId) { if (teamHttpContext == null) { throw new ArgumentNullException(nameof(teamHttpContext)); } string userId = LogoutuserId.ToUpper(CultureInfo.InvariantCulture); using (TeamDbContext dbContext = new TeamDbContext()) { List <UserSession> activeSessions = dbContext.UserSessions.Where(e => e.UserId == userId && !e.Deleted && e.Active).ToList(); foreach (UserSession item in activeSessions) { item.Active = false; await CacheService.RemoveSessionAsync(teamHttpContext, item.SessionId).ConfigureAwait(false); } await dbContext.SaveChangesAsync().ConfigureAwait(false); } await CacheService.RemoveUserAsync(teamHttpContext, LogoutuserId).ConfigureAwait(false); return(GetResponse(teamHttpContext)); }
internal static async Task LogAsync(TeamHttpContext teamContext, TeamDbContext dbContext, string parentType, string parentId, string name) { await LogAsync(teamContext, dbContext, parentType, parentId, name, null).ConfigureAwait(false); }
internal static async Task LogAsync(TeamHttpContext teamContext, TeamDbContext dbContext, string parentType, int parentId, string name) { await LogAsync(teamContext, dbContext, parentType, parentId.ToString(CultureInfo.InvariantCulture), name, null).ConfigureAwait(false); }
public static async Task <ResponseBase <List <AllWidgetDropDowns> > > DashboardAddDropDowns(TeamHttpContext teamHttpContext) { List <ChartTypes> objChartTypes = new List <ChartTypes>(); List <string> objUserList = new List <string>(); List <SchedulerTypes> objSchedulerTypes = new List <SchedulerTypes>(); List <DBConnectionStrings> objDBConnectionStrings = new List <DBConnectionStrings>(); List <AllWidgetDropDowns> objDashboardAddDropDowns = new List <AllWidgetDropDowns>(); using (TeamDbContext dbContext = new TeamDbContext()) { var charttypes = from ct in dbContext.ChartTypes select new { ChartId = ct.ChartId, ChartName = ct.ChartName }; foreach (var item in charttypes) { ChartTypes chartList = new ChartTypes { ChartId = item.ChartId, ChartName = item.ChartName }; objChartTypes.Add(chartList); } var userlists = from ul in dbContext.Users select new { UserId = ul.UserId }; foreach (var item in userlists) { objUserList.Add(item.UserId); } var schedulertypes = from sd in dbContext.Schedulers select new { Id = sd.Id, SchedulerName = sd.SchedulerName }; foreach (var item in schedulertypes) { SchedulerTypes schedulerType = new SchedulerTypes { SchedulerId = item.Id, SchedulerName = item.SchedulerName }; objSchedulerTypes.Add(schedulerType); } var dbconnectionstrings = from dbcs in dbContext.DBConnections select new { DBConnectionId = dbcs.DBConnectionId, DBConnectionName = dbcs.DBConnectionName }; foreach (var item in dbconnectionstrings) { DBConnectionStrings connectionList = new DBConnectionStrings { DBConnectionId = item.DBConnectionId, DBConnectionName = item.DBConnectionName }; objDBConnectionStrings.Add(connectionList); } } AllWidgetDropDowns finallist = new AllWidgetDropDowns { Charts = objChartTypes, Users = objUserList, Schedulers = objSchedulerTypes, ConnectionStrings = objDBConnectionStrings }; objDashboardAddDropDowns.Add(finallist); return(GetTypedResponse(teamHttpContext, objDashboardAddDropDowns)); }
public TeamsController(TeamDbContext context) { _context = context; }
public EmployeeRepository(TeamDbContext dbContext) { DbContext = dbContext; }
internal static async Task <List <OnScreenClick> > GetGridDataAsync(TeamHttpContext httpContext, OnScreenClick details) { //string connString = Utility.GetConnectionString("PgAdmin4ConnectionString"); string connString = string.Empty; string userid = httpContext.ContextUserId; //string userid = "Admin"; List <OnScreenClick> returnValue = new List <OnScreenClick>(); PostgresService postgresService = new PostgresService(); List <UserDashboard> objUserDashboard = new List <UserDashboard>(); string querylevel = string.Empty; List <string[]> ResultSet = new List <string[]>(); MatchCollection allMatchResults = null; Regex regex = new Regex(@"@\w*@"); using (TeamDbContext dbContext = new TeamDbContext()) { //objUserDashboard = dbContext.UserDashboards.Where(x => x.DashboardUserId == userid && x.Deleted == false && x.Id == details.ClickedWidgetId).ToList(); // For specific user objUserDashboard = dbContext.UserDashboards.Where(x => x.Deleted == false && x.Id == details.ClickedWidgetId).ToList(); // for all users } if (objUserDashboard.Count != 0) { foreach (var item in objUserDashboard) { switch (details.ClickLevel) { case "L1": connString = Utility.GetConnectionString(item.Level1ConnectionString); querylevel = item.DashbaordQueryL1; allMatchResults = regex.Matches(querylevel); if (allMatchResults.Count > 0) { querylevel = querylevel.Replace(allMatchResults[0].Value, details.ClickedOnValue); } break; case "L2": connString = Utility.GetConnectionString(item.Level2ConnectionString); querylevel = item.DashbaordQueryL2; break; case "L3": connString = Utility.GetConnectionString(item.Level3ConnectionString); querylevel = item.DashbaordQueryL3; break; case "L4": connString = Utility.GetConnectionString(item.Level4ConnectionString); querylevel = item.DashbaordQueryL4; break; } if (details.ClickLevel != "L1") { var dict = details.GridInput.ToDictionary(m => m.Name, m => m.Value); allMatchResults = regex.Matches(querylevel); if (allMatchResults.Count > 0) { foreach (var match in allMatchResults) { dict.TryGetValue(((System.Text.RegularExpressions.Capture)match).Value.Substring(1, ((System.Text.RegularExpressions.Capture)match).Value.Length - 2), out string result); querylevel = querylevel.Replace(match.ToString(), result); } } } NpgsqlDataReader dr = postgresService.ExecuteSqlReturnReader(connString, querylevel); DataTable dtSchema = dr.GetSchemaTable(); DataTable dt = new DataTable(); List <DataColumn> listCols = new List <DataColumn>(); if (dtSchema != null) { foreach (DataRow drow in dtSchema.Rows) { string columnName = Convert.ToString(drow["ColumnName"]); DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"])); column.Unique = (bool)drow["IsUnique"]; column.AutoIncrement = (bool)drow["IsAutoIncrement"]; listCols.Add(column); dt.Columns.Add(column); } } // Read rows from DataReader and populate the DataTable while (dr.Read()) { DataRow dataRow = dt.NewRow(); for (int i = 0; i < listCols.Count; i++) { dataRow[((DataColumn)listCols[i])] = dr[i]; } dt.Rows.Add(dataRow); } string[] columnNames = dt.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray(); ResultSet = dt.Select().Select(drr => drr.ItemArray.Select(x => x.ToString()).ToArray()).ToList(); OnScreenClick newItem = new OnScreenClick { ClickLevel = details.ClickLevel, ClickedWidgetId = details.ClickedWidgetId, ClickedOnValue = details.ClickedOnValue, GridColumns = columnNames, GridData = ResultSet, GridInput = null }; returnValue.Add(newItem); } } return(returnValue); }
internal static async Task <List <LoadWidgets> > GetWidgetAsync(TeamHttpContext httpContext, string widgettype, string widgetname)//, string widgetquery, string widgetquerylevel1, string widgetquerylevel2, string widgetquerylevel3, string widgetquerylevel4) { string userid = httpContext.ContextUserId; List <LoadWidgets> returnValue = new List <LoadWidgets>(); PostgresService postgresService = new PostgresService(); List <UserDashboard> objUserDashboard = new List <UserDashboard>(); using (TeamDbContext dbContext = new TeamDbContext()) { objUserDashboard = dbContext.UserDashboards.Where(x => x.CreatedBy == userid && x.DashboardChartType == widgettype && x.DashboardWidgetName == widgetname && x.Deleted == false).ToList(); } if (objUserDashboard.Count != 0) { foreach (var item in objUserDashboard) { List <WidgetRead> objWidgetRead = new List <WidgetRead>(); string connString = Utility.GetConnectionString(item.WidgetConnectionString); using (NpgsqlDataReader sqlData = postgresService.ExecuteSqlReturnReader(connString, item.WidgetQuery)) { while (sqlData.Read()) { objWidgetRead.Add(new WidgetRead { Name = sqlData.GetBlankStringIfNull("name"), Count = sqlData.GetInt32("count") }); } } LoadWidgets newItem = new LoadWidgets { DashboardWidgetName = item.DashboardWidgetName, WidgetId = item.Id, DashboardChartType = item.DashboardChartType, DashboardUserPermission = item.DashboardUserPermission, DashboardEmailFormat = item.DashboardEmailFormat, WidgetData = objWidgetRead.ToArray(), WidgetConnectionString = item.WidgetConnectionString, WidgetSchedulerType = item.WidgetSchedulerType, WidgetSchedulerEmailIDs = item.WidgetSchedulerEmailIDs, WidgetQuery = item.WidgetQuery, Level1ConnectionString = item.Level1ConnectionString, Level1SchedulerType = item.Level1SchedulerType, L1SchedulerEmailIDs = item.L1SchedulerEmailIDs, DashbaordQueryL1 = item.DashbaordQueryL1, Level2ConnectionString = item.Level2ConnectionString, Level2SchedulerType = item.Level2SchedulerType, L2SchedulerEmailIDs = item.L2SchedulerEmailIDs, DashbaordQueryL2 = item.DashbaordQueryL2, Level3ConnectionString = item.Level3ConnectionString, Level3SchedulerType = item.Level3SchedulerType, L3SchedulerEmailIDs = item.L3SchedulerEmailIDs, DashbaordQueryL3 = item.DashbaordQueryL3, Level4ConnectionString = item.Level4ConnectionString, Level4SchedulerType = item.Level4SchedulerType, L4SchedulerEmailIDs = item.L4SchedulerEmailIDs, DashbaordQueryL4 = item.DashbaordQueryL4, WidgetSendEmail = item.WidgetSendEmail }; returnValue.Add(newItem); } } return(returnValue); }
public TeamController(TeamDbContext teamDbContext) { this.teamDbContext = teamDbContext; }
public static async Task <ResponseBase <List <ReportGrid> > > ViewReport(TeamHttpContext teamHttpContext, int reportId) { try { //string connString = Utility.GetConnectionString("PgAdmin4ConnectionString"); string userid = teamHttpContext.ContextUserId; //string userid = "Admin"; List <ReportGrid> returnValue = new List <ReportGrid>(); PostgresService postgresService = new PostgresService(); List <ReportConfig> objReportConfig = new List <ReportConfig>(); List <string[]> ResultSet = new List <string[]>(); using (TeamDbContext dbContext = new TeamDbContext()) { objReportConfig = dbContext.ReportConfigs.Where(x => x.Id == reportId && x.Deleted == false && x.ReportReqUserId == userid).ToList(); } if (objReportConfig.Count != 0) { foreach (var item in objReportConfig) { string connString = Utility.GetConnectionString(item.ReportConnectionString); NpgsqlDataReader dr = postgresService.ExecuteSqlReturnReader(connString, item.ReportQuery); DataTable dtSchema = dr.GetSchemaTable(); DataTable dt = new DataTable(); List <DataColumn> listCols = new List <DataColumn>(); if (dtSchema != null) { foreach (DataRow drow in dtSchema.Rows) { string columnName = Convert.ToString(drow["ColumnName"]); DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"])); column.Unique = (bool)drow["IsUnique"]; column.AutoIncrement = (bool)drow["IsAutoIncrement"]; listCols.Add(column); dt.Columns.Add(column); } } // Read rows from DataReader and populate the DataTable while (dr.Read()) { DataRow dataRow = dt.NewRow(); for (int i = 0; i < listCols.Count; i++) { dataRow[((DataColumn)listCols[i])] = dr[i]; } dt.Rows.Add(dataRow); } string[] columnNames = dt.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToArray(); ResultSet = dt.Select().Select(drr => drr.ItemArray.Select(x => x.ToString()).ToArray()).ToList(); ReportGrid newItem = new ReportGrid { ReportId = reportId, ReportName = item.ReportName, GridColumns = columnNames, GridData = ResultSet, IsActive = !(item.Deleted) }; returnValue.Add(newItem); } } return(GetTypedResponse(teamHttpContext, returnValue)); } catch (Exception) { return(null); } }
public DatabaseSeeder(TeamDbContext context) { _context = context; }
public static async Task <ResponseBase <LoginResponseModel> > LoginAsync(TeamHttpContext teamHttpContext, LoginModel loginModel) { if (teamHttpContext == null) { throw new ArgumentNullException(nameof(teamHttpContext)); } if (loginModel == null) { throw new ArgumentNullException(nameof(loginModel)); } LoginResponseModel loginResponse = new LoginResponseModel { Status = LoginStatus.InValid }; User user = new User(); user = await ValidatePassword(teamHttpContext, loginModel).ConfigureAwait(false); if (user != null) { using (TeamDbContext dbContext = new TeamDbContext()) { if (user.UserId != null) { teamHttpContext.SetValue(Constants.CONTEXT_USER_ID, user.UserId); loginResponse.Status = LoginStatus.LoggedIn; } else { loginResponse.Status = LoginStatus.NoAccess; } if (loginResponse.Status == LoginStatus.LoggedIn) { user.LastLoggedIn = DateTime.Now; await dbContext.SaveChangesAsync().ConfigureAwait(false); } } } if (loginResponse.Status == LoginStatus.LoggedIn) { string sessionId = Guid.NewGuid().ToString(); await CreateSessionAsync(user.UserId, sessionId).ConfigureAwait(false); await CacheService.StoreSessionAsync(teamHttpContext, sessionId).ConfigureAwait(false); await CacheService.StoreUserAsync(teamHttpContext, user).ConfigureAwait(false); int validity = Utility.IsProduction ? 1 : 7; long validUntil = DateTime.UtcNow.AddDays(validity).GetUnixTimeStamp(); loginResponse.Token = Jwt.CreateToken(user, sessionId, validUntil); loginResponse.Email = user.Email; loginResponse.UserId = user.UserId; loginResponse.Type = user.UserType; loginResponse.SessionId = sessionId; loginResponse.ExpiryTimestamp = validUntil; loginResponse.IsAddRights = user.IsAdd; loginResponse.IsEditRights = user.IsEdit; loginResponse.IsDeleteRights = user.IsDelete; return(GetTypedResponse <LoginResponseModel>(teamHttpContext, loginResponse)); } else { return(GetUnauthorizedResponse <LoginResponseModel>(teamHttpContext, loginResponse)); } }