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)); }
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 void Seed(SqlConfidenceContext context) { if (context.DataSources.Any()) { return; } context.DataSources.Add( new DataSource { Name = "Staff", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, DataSourceTables = new List <DataSourceTable>() { new DataSourceTable() { TableName = "SRC_ORGANISATIONS_AND_STAFF", CreatedBy = "SeedScript", CreatedDate = DateTime.Now } } }); context.SaveChanges(); }
public void PutExerciseToServer(int ExerciseId) { var serverDA = new ServerDataAccess(); var context = new SqlConfidenceContext(); var exercise = context.Exercises.Find(ExerciseId); serverDA.PutExercise(exercise); }
public void Seed(SqlConfidenceContext context) { // This seed script is for local use only, so only create for blank databases if (context.QueryExercises.Any()) { return; } var staffDataSourceId = context.DataSources.Single(x => x.Name == "Staff").Id; var section = new Section() { Name = "Query Questions Section", Description = "This section containts the query exercises" }; context.Sections.Add(section); context.SaveChanges(); var exercise = new QueryExercise { DataSourceId = staffDataSourceId, Name = "Query Exercise Example", Summary = "This exercise demonstrates the query exercise type", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, PublishedBy = "SeedScript", Order = 1, Section = section }; context.QueryExercises.Add(exercise); context.SaveChanges(); var question = new QueryQuestion { Description = "Select everything from the table ORGANISATIONS_AND_STAFF", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Order = 0, Exercise = exercise, CorrectAnswerQuery = "SELECT * FROM ORGANISATIONS_AND_STAFF" }; context.QueryQuestions.Add(question); context.SaveChanges(); }
public ActionResult NewDataSource(DataSource DataSource) { if (!String.IsNullOrEmpty(DataSource.Name)) { DataSource.CreatedBy = GetCurrentUser().Email; DataSource.CreatedDate = DateTime.Now; DataSource.DataSourceIdGuid = Guid.NewGuid(); SqlConfidenceContext context = new SqlConfidenceContext(); context.DataSources.Add(DataSource); context.SaveChanges(); return(RedirectToAction("DataSource", new { DataSourceId = DataSource.DataSourceId, SuccessMessage = "Data Source saved Successfully" })); } return(View()); }
public void Seed(SqlConfidenceContext context) { context.Users.AddOrUpdate( x => x.Email, new User { FirstName = "Admin", LastName = "User", Email = "*****@*****.**", CreatedDate = DateTime.Now, CreatedBy = "SeedScript", IsAdmin = true, Password = "******" //Password }); context.SaveChanges(); }
public void Seed(SqlConfidenceContext context) { context.UserActionTypes.AddOrUpdate( x => x.Id, new UserActionType { Id = 0, Description = "Execute Query" }, new UserActionType { Id = 1, Description = "Check Answer" } ); context.SaveChanges(); }
public void Seed(SqlConfidenceContext context) { context.DataSources.AddOrUpdate(x => x.Name, new DataSource { Name = "Staff", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, DataSourceTables = new List <DataSourceTable>() { new DataSourceTable() { TableName = "SRC_ORGANISATIONS_AND_STAFF", TableAlias = "ORGANISATIONS_AND_STAFF", CreatedBy = "SeedScript", CreatedDate = DateTime.Now } } }); context.SaveChanges(); }
public void Save(ExerciseQuestionAnswered QuestionAnswered) { // Does it already exist? var exists = QuestionAnswered.ExerciseQuestionAnsweredId != 0; var context = new SqlConfidenceContext(); // Stop it saving any related objects QuestionAnswered.ExerciseQuestion = null; if (!exists) { context.ExerciseQuestionAnswereds.Add(QuestionAnswered); } else { context.ExerciseQuestionAnswereds.Attach(QuestionAnswered); context.Entry(QuestionAnswered).State = EntityState.Modified; } context.SaveChanges(); }
public void Save(DataSourceTable DataSourceTable) { // Does it already exist? var exists = DataSourceTable.DataSourceTableId != 0; var context = new SqlConfidenceContext(); // Stop it saving any related objects DataSourceTable.DataSource = null; if (!exists) { context.DataSourceTables.Add(DataSourceTable); } else { context.DataSourceTables.Attach(DataSourceTable); context.Entry(DataSourceTable).State = EntityState.Modified; } context.SaveChanges(); }
public void Seed(SqlConfidenceContext context) { if (context.UserActionTypes.Any()) { return; } context.UserActionTypes.Add( new UserActionType { Description = "Execute Query" } ); context.UserActionTypes.Add( new UserActionType { Description = "Check Answer" } ); context.SaveChanges(); }
public void Save(ExerciseQuestionChoice Choice) { // Does it already exist? var exists = Choice.ExerciseQuestionChoiceId != Guid.Empty; var context = new SqlConfidenceContext(); // Stop it saving any related objects Choice.ExerciseQuestion = null; if (!exists) { Choice.ExerciseQuestionChoiceId = Guid.NewGuid(); context.ExerciseQuestionChoices.Add(Choice); } else { context.ExerciseQuestionChoices.Attach(Choice); context.Entry(Choice).State = EntityState.Modified; } context.SaveChanges(); }
public EntityRepository(SqlConfidenceContext context, IEntityIncludes <T> includes) : base(context, includes) { }
public void Seed(SqlConfidenceContext context) { // This seed script is for local use only, so only create for blank databases if (context.Exercises.Any()) { return; } var multipleChoiceSectionName = "Multiple Choice Exercises"; var staffDataSourceId = context.DataSources.Single(x => x.Name == "Staff").DataSourceId; var staffDataQuery = new MultipleChoiceDataQuery() { SqlQuery = "SELECT name, organisation_name, gender, salary, years_at_company, sick_days_taken, holiday_days_left, performance FROM ORGANISATIONS_AND_STAFF" }; var exercise = new MultipleChoiceExercise { DataSourceId = staffDataSourceId, Name = "Multiple Choice Example", Summary = "This exercise demonstrates the multiple choice exercise type", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Published = true, PublishedDate = DateTime.Now, PublishedBy = "SeedScript", Order = 0, SectionName = multipleChoiceSectionName, DataQueries = new List <MultipleChoiceDataQuery>() { staffDataQuery } }; context.MultipleChoiceExercises.AddOrUpdate( x => x.Name, exercise ); context.SaveChanges(); var question = new MultipleChoiceQuestion { Description = "Salary Data Type", InstructionsTemplate = "What kind of data type is the salary column?", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Order = 0, Options = new List <MultipleChoiceOption>() { new MultipleChoiceOption { Description = "varchar", IncorrectAnswerMessage = "Salaries are number of some kind" }, new MultipleChoiceOption { Description = "int", CorrectAnswerMessage = "Correct! Salaries are numbers with no decimal places, which makes them integers." }, new MultipleChoiceOption { Description = "numeric", IncorrectAnswerMessage = "The numeric data type contains decimal places, salaries have no decimals" } }, DataQueries = new List <MultipleChoiceDataQuery>() { staffDataQuery }, Exercise = exercise }; context.MultipleChoiceQuestions.AddOrUpdate( x => x.Description, question ); context.SaveChanges(); question.CorrectOption = question.Options.Single(x => !String.IsNullOrEmpty(x.CorrectAnswerMessage)); context.SaveChanges(); }
public void Seed(SqlConfidenceContext context) { // This seed script is for local use only, so only create for blank databases if (context.MultipleChoiceExercises.Any()) { return; } var staffDataSourceId = context.DataSources.Single(x => x.Name == "Staff").Id; var section = new Section() { Name = "Multiple Choice Section", Description = "This section has the multiple choice exercises in it" }; context.Sections.Add(section); context.SaveChanges(); var exercise = new MultipleChoiceExercise { DataSourceId = staffDataSourceId, Name = "Multiple Choice Example", Summary = "This exercise demonstrates the multiple choice exercise type", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Published = true, PublishedDate = DateTime.Now, PublishedBy = "SeedScript", Section = section, Order = 0 }; context.MultipleChoiceExercises.Add(exercise); context.SaveChanges(); var question = new MultipleChoiceQuestion { Description = "Salary Data Type", Instructions = "What kind of data type is the salary column?", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Order = 0, Options = new List <MultipleChoiceOption>() { new MultipleChoiceOption { Description = "varchar", IncorrectAnswerMessage = "Salaries are number of some kind" }, new MultipleChoiceOption { Description = "int", CorrectAnswerMessage = "Salaries are numbers with no decimal places, which makes them integers." }, new MultipleChoiceOption { Description = "numeric", IncorrectAnswerMessage = "The numeric data type contains decimal places, salaries have no decimals" } }, DataQueries = new List <MultipleChoiceDataQuery>() { new MultipleChoiceDataQuery() { SqlQuery = "SELECT TOP 10 name, organisation_name, gender, salary, years_at_company, sick_days_taken, holiday_days_left, performance FROM ORGANISATIONS_AND_STAFF" } }, Exercise = exercise }; context.MultipleChoiceQuestions.Add(question); context.SaveChanges(); question.CorrectOption = question.Options.Single(x => !String.IsNullOrEmpty(x.CorrectAnswerMessage)); context.SaveChanges(); var questionTwo = new MultipleChoiceQuestion { Description = "Gender Data Type", Instructions = "What kind of data type is the gender column?", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Order = 1, Options = new List <MultipleChoiceOption>() { new MultipleChoiceOption { Description = "varchar", CorrectAnswerMessage = "The gender column is a varchar column." }, new MultipleChoiceOption { Description = "int", IncorrectAnswerMessage = "Please try again." }, new MultipleChoiceOption { Description = "numeric", IncorrectAnswerMessage = "Please try again." } }, DataQueries = new List <MultipleChoiceDataQuery>() { new MultipleChoiceDataQuery() { SqlQuery = "SELECT TOP 10 name, organisation_name, gender, salary, years_at_company, sick_days_taken, holiday_days_left, performance FROM ORGANISATIONS_AND_STAFF" } }, Exercise = exercise }; context.MultipleChoiceQuestions.Add(questionTwo); context.SaveChanges(); questionTwo.CorrectOption = questionTwo.Options.Single(x => !String.IsNullOrEmpty(x.CorrectAnswerMessage)); context.SaveChanges(); var questionThree = new MultipleChoiceQuestion { Description = "Salary Data Type", Instructions = "What kind of data type is the holiday_days_left column?", CreatedBy = "SeedScript", CreatedDate = DateTime.Now, Order = 2, Options = new List <MultipleChoiceOption>() { new MultipleChoiceOption { Description = "varchar", IncorrectAnswerMessage = "Please try again." }, new MultipleChoiceOption { Description = "int", IncorrectAnswerMessage = "The int data type is a whole number, which is not right here." }, new MultipleChoiceOption { Description = "numeric", CorrectAnswerMessage = "Well done! The data has decimals, so it's numeric." } }, DataQueries = new List <MultipleChoiceDataQuery>() { new MultipleChoiceDataQuery() { SqlQuery = "SELECT TOP 10 name, organisation_name, gender, salary, years_at_company, sick_days_taken, holiday_days_left, performance FROM ORGANISATIONS_AND_STAFF" } }, Exercise = exercise }; context.MultipleChoiceQuestions.Add(questionThree); context.SaveChanges(); questionThree.CorrectOption = questionThree.Options.Single(x => !String.IsNullOrEmpty(x.CorrectAnswerMessage)); context.SaveChanges(); }
public UserRepository() { _context = new SqlConfidenceContext(); }
public EntityRepository() { _context = new SqlConfidenceContext(); }
public ExerciseRepository() { _context = new SqlConfidenceContext(); }
public Repository(SqlConfidenceContext context, IEntityIncludes <T> includes) { _context = context; _includes = includes; }