public JsonResult AddDataSourceTable(int DataSourceId, string TableName) { Object returnData; try { ISourceDataAccess dataAccess = SourceDataAccessFactory.CreateDataAccess(Common.Enums.SourceDatabaseType.TSQL); TableModel table = dataAccess.ListAllTables().Single(x => x.TableName == TableName); DataSourceTable dsTable = new DataSourceTable(); dsTable.DataSourceId = DataSourceId; dsTable.CreatedBy = GetCurrentUser().Email; dsTable.CreatedDate = DateTime.Now; dsTable.DataSourceTableIdGuid = Guid.NewGuid(); dsTable.TableAlias = table.TableName.Replace("SRC_", ""); dsTable.TableName = table.TableName; dsTable.Columns = new JavaScriptSerializer().Serialize(table.Columns); SqlConfidenceContext context = new SqlConfidenceContext(); context.DataSourceTables.Add(dsTable); context.SaveChanges(); returnData = new { Success = true }; return(Json(returnData)); } catch (Exception ex) { returnData = new { Success = false, ErrorMessage = "Error adding table, please check the logs" }; Trace.WriteLine(String.Format("Error adding table {0} to {1} - {2}", TableName, DataSourceId, ex.Message)); return(Json(returnData)); } }
public ActionResult DataSource(DataSource DataSource) { SqlConfidenceContext context = new SqlConfidenceContext(); if (!String.IsNullOrEmpty(DataSource.Name)) { try { var original = context.DataSources.Find(DataSource.DataSourceId); context.Entry(original).CurrentValues.SetValues(DataSource); original.UpdatedBy = GetCurrentUser().Email; original.UpdatedDate = DateTime.Now; context.SaveChanges(); ViewBag.SuccessMessage = "Saved Successfully"; } catch (Exception ex) { Trace.WriteLine("Error saving exercise - " + ex.Message); ViewBag.ErrorMessage = "Error saving exercise, please check the logs"; } } DataSource = context.DataSources.Single(x => x.DataSourceId == DataSource.DataSourceId); ISourceDataAccess dataAccess = SourceDataAccessFactory.CreateDataAccess(Common.Enums.SourceDatabaseType.TSQL); ViewBag.Tables = dataAccess.ListAllTables(); return(View(DataSource)); }