public async Task <ExecutionStatus> Run(CategoryUniqueId categoryId)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            var q = @"DELETE FROM Categories WHERE UniqueId=@UniqueId;";

            try
            {
                var result = await connection.QueryAsync <int>(q,
                                                               new
                {
                    @UniqueId = categoryId.Value.ToString()
                });
            }
            catch (Exception ex)
            {
                if (ExecutionFlow.Options.ThrowExceptions)
                {
                    throw;
                }

                return(ExecutionStatus.DbError(ex));
            }

            return(ExecutionStatus.DbOk());
        }
Beispiel #2
0
        public async Task <ExecutionStatus> Run(CallForSpeechId id, JudgeId judge, CallForSpeechStatus status)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            var q = @"UPDATE CallForSpeakes
                SET FinalDecision_DecisionBy = @JudgeId,
                FinalDecision_Date = @Date,
                Status = @Status
                WHERE Id = @Id;";

            try
            {
                var result = await connection.ExecuteAsync(q,
                                                           new
                {
                    @JudgeId = judge.Value,
                    @Date    = AppTime.Now().ToLongDateString(),
                    @Id      = id.Value,
                    @Status  = (int)status
                });

                return(ExecutionStatus.DbOk());
            }
            catch (Exception ex)
            {
                if (ExecutionFlow.Options.ThrowExceptions)
                {
                    throw;
                }

                return(ExecutionStatus.DbError(ex));
            }
        }
Beispiel #3
0
        Run(CallForSpeech callForSpeech)
        {
            var temp = _mapper.Map <CallForSpeechTemp>(callForSpeech);

            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            var q = SqlQueries.CallForSpeechInsert;

            try
            {
                var result = await connection.QueryAsync <int>(q, temp);

                int createdId = result.FirstOrDefault();

                CallForSpeechIds ids = new CallForSpeechIds()
                {
                    CreatedId = new CallForSpeechId(createdId),
                    UniqueId  = callForSpeech.UniqueId
                };

                return(ExecutionStatus <CallForSpeechIds> .DbOk(ids));
            }
            catch (Exception ex)
            {
                if (ExecutionFlow.Options.ThrowExceptions)
                {
                    throw;
                }

                return(ExecutionStatus <CallForSpeechIds> .DbError(ex));
            }
        }
        public async Task <ExecutionStatus> Run(Judge entity, ByWhatId byWhatId)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            //Nie ma SQL INjection
            var q2 = @"UPDATE Judges 
                SET Login = @Login, Password = @Password, BirthDate=@BirthDate  
                ,Name_First = @Name_First, Name_Last = @Name_Last
                WHERE Id = @Id; ";
            var q  = @"UPDATE Judges 
                SET Login = @Login, Password = @Password, BirthDate=@BirthDate  
                ,Name_First = @Name_First, Name_Last = @Name_Last
                WHERE UniqueId = @UniqueId; ";

            var temp = _mapper.Map <JudgeTemp>(entity);

            try
            {
                if (byWhatId == ByWhatId.CreatedId)
                {
                    q = q2;
                }

                var result = await connection.ExecuteAsync(q, temp);

                return(ExecutionStatus.DbOk());
            }
            catch (Exception ex)
            {
                return(ExecutionStatus.DbError(ex.Message));
            }
        }
        public async Task <ExecutionStatus <CategoryIds> > Run(Category entity)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            //Nie ma SQL INjection
            var q = @"INSERT INTO Categories(Name, DisplayName, WhatWeAreLookingFor
                ,UniqueId, Version)
                VALUES (@Name, @DisplayName, @WhatWeAreLookingFor,@UniqueId, @Version);
                SELECT seq From sqlite_sequence Where Name='Categories'";

            try
            {
                var result = await connection.QueryAsync <int>(q,
                                                               new
                {
                    @Name                = entity.Name,
                    @DisplayName         = entity.DisplayName,
                    @WhatWeAreLookingFor = entity.WhatWeAreLookingFor,
                    @UniqueId            = entity.UniqueId.Value.ToString(),
                    @Version             = entity.Version,
                });

                //var cmd = connection.CreateCommand();
                //cmd.CommandText = "SELECT last_insert_rowid()";
                //Int64 i = (Int64)cmd.ExecuteScalar();

                int createdId = result.FirstOrDefault();

                CategoryIds ids = new CategoryIds()
                {
                    CreatedId = new CategoryId(createdId),
                    UniqueId  = entity.UniqueId
                };

                return(ExecutionStatus
                       <CategoryIds>
                       .DbOk(ids));
            }
            catch (Exception ex)
            {
                if (ExecutionFlow.Options.ThrowExceptions)
                {
                    throw;
                }

                return(ExecutionStatus
                       <CategoryIds>
                       .DbError(ex));
            }
        }
        public async Task <ExecutionStatus> Run(Category entity, ByWhatId byWhatId)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            //Nie ma SQL INjection
            var q1 = @"UPDATE Categories 
                SET Name = @Name, DisplayName = @DisplayName, WhatWeAreLookingFor=@WhatWeAreLookingFor
                ,Version = @Version
                WHERE UniqueId = @UniqueId; ";

            var q = @"UPDATE Categories 
                SET Name = @Name, DisplayName = @DisplayName, WhatWeAreLookingFor=@WhatWeAreLookingFor
                ,Version = @Version
                WHERE Id = @Id; ";

            try
            {
                if (byWhatId == ByWhatId.UniqueId)
                {
                    q = q1;
                }

                var result = await connection.QueryAsync <int>(q,
                                                               new
                {
                    @UniqueId            = entity.UniqueId.Value.ToString(),
                    @Id                  = entity.Id.Value,
                    @Name                = entity.Name,
                    @Version             = entity.Version,
                    @DisplayName         = entity.DisplayName,
                    @WhatWeAreLookingFor = entity.WhatWeAreLookingFor
                });

                return(ExecutionStatus.DbOk());
            }
            catch (Exception ex)
            {
                if (ExecutionFlow.Options.ThrowExceptions)
                {
                    throw;
                }

                return(ExecutionStatus.DbError(ex));
            }
        }
Beispiel #7
0
        public async Task <ExecutionStatus> Run(JudgeUniqueId id)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            var q = "DELETE FROM Judges WHERE UniqueId=@UniqueId;";

            try
            {
                var result = await connection.QueryAsync <int>(q,
                                                               new
                {
                    @UniqueId = id.Value.ToString()
                });

                return(ExecutionStatus.DbOk());
            }
            catch (Exception ex)
            {
                return(ExecutionStatus.DbError(ex.Message));
            }
        }
Beispiel #8
0
        public async Task <ExecutionStatus> Run(CallForSpeechId id,
                                                CallForSpeechScoringResult score, CallForSpeechStatus status)
        {
            using var connection = new SqliteConnection(_geekLemonContext.ConnectionString);

            var q = @"UPDATE CallForSpeakes
                SET Score_Score = @Score, 
                Score_RejectExplanation = @RejectExplanation,
                Score_WarringExplanation = @WarringExplanation,
                Status = @Status
                WHERE Id = @Id;";

            try
            {
                var result = await connection.ExecuteAsync(q,
                                                           new
                {
                    @Score = (int)score.Score,
                    @WarringExplanation = score.WarringExplanation,
                    @RejectExplanation  = score.RejectExplanation,
                    @Id     = id.Value,
                    @Status = (int)status
                });

                return(ExecutionStatus.DbOk());
            }
            catch (Exception ex)
            {
                if (ExecutionFlow.Options.ThrowExceptions)
                {
                    throw;
                }

                return(ExecutionStatus.DbError(ex));
            }
        }