Esempio n. 1
0
        public static Question Select(Guid questionId)
        {
            var sqlInteractor = new SqliteInteractor();

            Question baseObject = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                         connection.QuerySingle <Question>(@"SELECT [Id], [QuestionText] FROM [Questions] WHERE [Id] = @Id", new { Id = questionId })
                                                                         );

            baseObject.Answer = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                       connection.Query <AnswerKey>(
                                                                           @"SELECT [Id], [Text], [Description], [Order], [QuestionId] FROM [AnswerKeys] WHERE [QuestionId] = @QuestionId",
                                                                           new { QuestionId = questionId }).OrderByDescending(ak => ak.Order)
                                                                       );

            var questionType = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                      connection.QuerySingle <Guid>(@"SELECT [QuestionTypeId] FROM [Questions] WHERE [Id] = @Id", new { Id = questionId })
                                                                      );

            baseObject.Type = QuestionType.Select(questionType);

            var questionDifficulty = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                            connection.QuerySingle <Guid>(@"SELECT [QuestionDifficultyId] FROM [Questions] WHERE [Id] = @Id", new { Id = questionId })
                                                                            );

            baseObject.Difficulty = QuestionDifficulty.Select(questionDifficulty);

            baseObject.Category = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                         connection.QuerySingle <Category>(
                                                                             @"SELECT [Categories].[Id], [Categories].[Name] FROM [Questions] LEFT OUTER JOIN [Categories] ON [Categories].[Id] = [Questions].[CategoryId] WHERE [Questions].[Id] = @Id",
                                                                             new { Id = questionId }
                                                                             )
                                                                         );

            return(baseObject);
        }
Esempio n. 2
0
        public Guid Insert()
        {
            var sqlInteractor = new SqliteInteractor();

            var questionId = this.Id;

            sqlInteractor.PerformDatabaseOperation((connection) =>
                                                   connection.ExecuteScalarQuery <Guid>(
                                                       @"INSERT INTO Questions (Id, QuestionText, QuestionTypeId, QuestionDifficultyId, CategoryId) VALUES (@Id, @QuestionText, @QuestionTypeId, @QuestionDifficultyId, @CategoryId);",
                                                       new
            {
                Id                   = questionId,
                QuestionText         = this.QuestionText,
                QuestionTypeId       = this.Type.Id,
                QuestionDifficultyId = this.Difficulty.Id,
                CategoryId           = this.Category.Id
            }
                                                       )
                                                   );

            foreach (var answerKey in this.Answer)
            {
                answerKey.QuestionId = questionId;
                answerKey.Insert();
            }

            return(questionId);
        }
Esempio n. 3
0
        public bool Delete()
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Delete(this)
                                                          ));
        }
Esempio n. 4
0
        public static Location Select(string locationName)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.GetAll <Location>().FirstOrDefault(l => l.Name.Equals(locationName, StringComparison.InvariantCultureIgnoreCase))
                                                          ));
        }
Esempio n. 5
0
        public static QuestionType Select(Guid typeId)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Get <QuestionType>(typeId)
                                                          ));
        }
Esempio n. 6
0
        public static QuestionType Select(string typeName)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.GetAll <QuestionType>().FirstOrDefault(t => t.Name.Equals(typeName, StringComparison.InvariantCultureIgnoreCase))
                                                          ));
        }
Esempio n. 7
0
        public static Category Select(Guid categoryId)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Get <Category>(categoryId)
                                                          ));
        }
        public void Update()
        {
            var sqlInteractor = new SqliteInteractor();

            sqlInteractor.PerformDatabaseOperation((connection) =>
                                                   connection.Update(this)
                                                   );
        }
Esempio n. 9
0
        public static IEnumerable <Address> Select()
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Query <Address>(@"SELECT [Id], [Address1], [Address2], [City], [State], [ZipCode], [SpecialDirections] FROM [Addresses]")
                                                          ));
        }
        public static IEnumerable <QuestionDifficulty> Select()
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.GetAll <QuestionDifficulty>()
                                                          ));
        }
        public static QuestionDifficulty Select(Guid difficultyId)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Get <QuestionDifficulty>(difficultyId)
                                                          ));
        }
Esempio n. 12
0
        public static Team Select(Guid teamId)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Get <Team>(teamId)
                                                          ));
        }
Esempio n. 13
0
        private int GetCountOfTeamsWithName()
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.GetAll <Team>().Count(team => team.Name == this.Name)
                                                          ));
        }
Esempio n. 14
0
        public static Category Select(string categoryName)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.GetAll <Category>()
                                                          .FirstOrDefault(category => category.Name.Equals(categoryName, StringComparison.InvariantCultureIgnoreCase))
                                                          ));
        }
        public static QuestionDifficulty Select(string difficultyName)
        {
            var sqlInteractor = new SqliteInteractor();

            return
                (sqlInteractor.PerformDatabaseOperation((connection) =>
                                                        connection.GetAll <QuestionDifficulty>()
                                                        .FirstOrDefault(d => d.Name.Equals(difficultyName, StringComparison.InvariantCultureIgnoreCase))
                                                        ));
        }
Esempio n. 16
0
        public void Insert()
        {
            var sqlInteractor = new SqliteInteractor();

            sqlInteractor.PerformDatabaseOperation((connection) =>
                                                   connection.ExecuteNonQuery(
                                                       "INSERT INTO [QuestionHistory] (QuestionId, [DateUsed], [_LocationId]) VALUES (@QuestionId, @DateUsed, @LocationId)",
                                                       new { QuestionId = this.QuestionId, DateUsed = this.DateUsed, LocationId = this.Location.Id })
                                                   );
        }
Esempio n. 17
0
        public Address Select(Guid locationId)
        {
            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.QuerySingle <Address>(
                                                              @"SELECT [Id], [Address1], [Address2], [City], [State], [ZipCode], [SpecialDirections], [LocationId] FROM [Addresses] WHERE [LocationId] = @Id",
                                                              new { Id = locationId }
                                                              )
                                                          ));
        }
Esempio n. 18
0
        public void Update()
        {
            var sqlInteractor = new SqliteInteractor();

            if (GetCountOfTeamsWithName() == 0)
            {
                sqlInteractor.PerformDatabaseOperation((connection) =>
                                                       connection.Update(this)
                                                       );
            }
        }
Esempio n. 19
0
        public void Update()
        {
            var sqlInteractor = new SqliteInteractor();

            sqlInteractor.PerformDatabaseOperation((connection) =>
                                                   connection.ExecuteNonQuery(
                                                       @"UPDATE [Locations] SET [Name] = @Name, [Phone] = @Phone WHERE [Id] = @LocationId",
                                                       new { Name = this.Name, Phone = this.Phone, LocationId = this.Id }
                                                       )
                                                   );

            Address.Update();
        }
Esempio n. 20
0
        public bool Delete()
        {
            foreach (var answerKey in this.Answer)
            {
                answerKey.Delete();
            }

            var sqlInteractor = new SqliteInteractor();

            return(sqlInteractor.PerformDatabaseOperation((connection) =>
                                                          connection.Delete(this)
                                                          ));
        }
Esempio n. 21
0
        public void Insert()
        {
            var sqlInteractor = new SqliteInteractor();

            if (GetCountOfTeamsWithName() == 0)
            {
                sqlInteractor.PerformDatabaseOperation((connection) =>
                                                       connection.Insert(new Team()
                {
                    Name = this.Name
                })
                                                       );
            }
        }
Esempio n. 22
0
        public Guid Insert()
        {
            var sqlInteractor = new SqliteInteractor();

            var locationId = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                    connection.ExecuteScalarQuery <Guid>(
                                                                        @"INSERT INTO [Locations] ([Id], [Name], [Phone]) VALUES (@Id, @Name, @Phone)",
                                                                        new { Id = Id, Name = this.Name, Phone = this.Phone }
                                                                        )
                                                                    );

            Address.Insert(Id);

            return(locationId);
        }
Esempio n. 23
0
        public static IEnumerable <Location> Select()
        {
            var sqlInteractor = new SqliteInteractor();

            var baseLocations = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                       connection.Query <Location>(@"SELECT [Id], [Name], [Phone] FROM [Locations]")
                                                                       );

            foreach (var baseLocation in baseLocations)
            {
                baseLocation.Address = baseLocation.Address.Select(baseLocation.Id);
            }

            return(baseLocations);
        }
Esempio n. 24
0
        public static Location Select(int locationId)
        {
            var sqlInteractor = new SqliteInteractor();

            var location = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                  connection.QuerySingle <Location>(
                                                                      @"SELECT [Id], [Name], [Phone] FROM [Locations] WHERE [Id] = @LocationId",
                                                                      new { LocationId = locationId }
                                                                      )
                                                                  );

            location.Address = location.Address.Select(location.Id);

            return(location);
        }
Esempio n. 25
0
        public static Question GetRandomQuestionByDifficulty(Guid difficulty)
        {
            var sqlInteractor = new SqliteInteractor();

            var commandParameters = new { difficultyId = difficulty };
            var commandDefinition = new CommandDefinition(
                "SELECT Id FROM [Questions] WHERE [QuestionDifficultyId] = @difficultyId ORDER BY RANDOM() LIMIT 1",
                commandParameters
                );

            var questionId = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                    connection.ExecuteScalar <Guid>(commandDefinition)
                                                                    );

            return
                (Select(questionId));
        }
Esempio n. 26
0
        public void Update()
        {
            var sqlInteractor = new SqliteInteractor();

            sqlInteractor.PerformDatabaseOperation((connection) =>
                                                   connection.ExecuteNonQuery(
                                                       @"UPDATE [Addresses] SET [Address1] = @Address1, [Address2] = @Address2, [City] = @City, [State] = @State, [ZipCode] = @ZipCode, [SpecialDirections] = @SpecialDirections 
			WHERE [Id] = @AddressId"            ,
                                                       new
            {
                Address1          = this.Address1,
                Address2          = this.Address2,
                City              = this.City,
                State             = this.State,
                ZipCode           = this.ZipCode,
                SpecialDirections = this.SpecialDirections,
                AddressId         = this.Id
            }
                                                       )
                                                   );
        }
Esempio n. 27
0
        public void Update()
        {
            var sqlInteractor = new SqliteInteractor();

            sqlInteractor.PerformDatabaseOperation((connection) =>
                                                   connection.ExecuteNonQuery(
                                                       @"UPDATE [Questions] SET [QuestionText] = @QuestionText, [QuestionTypeId] = @QuestionType, [QuestionDifficultyId] = @Difficulty, [CategoryId] = @CategoryId WHERE [QuestionId] = @QuestionId",
                                                       new
            {
                QuestionText = this.QuestionText,
                QuestionType = this.Type.Id,
                Difficulty   = this.Type.Id,
                CategoryId   = this.Category,
                QuestionId   = this.Id
            }
                                                       ));

            foreach (var answerKey in Answer)
            {
                answerKey.Update();
            }
        }
Esempio n. 28
0
        public Guid Insert(Guid locationId)
        {
            var sqlInteractor = new SqliteInteractor();

            var addressId = sqlInteractor.PerformDatabaseOperation((connection) =>
                                                                   connection.ExecuteScalarQuery <Guid>(
                                                                       @"INSERT INTO [Addresses] ([Id], [Address1], [Address2], [City], [State], [ZipCode], [SpecialDirections], [LocationId])
			VALUES (@Id, @Address1, @Address2, @City, @State, @ZipCode, @SpecialDirections, @LocationId)"            ,
                                                                       new
            {
                Id                = Id,
                Address1          = this.Address1,
                Address2          = this.Address2,
                City              = this.City,
                State             = this.State,
                ZipCode           = this.ZipCode,
                SpecialDirections = this.SpecialDirections,
                locationId
            }
                                                                       )
                                                                   );

            return(addressId);
        }