Example #1
0
        public async Task <bool> UpdateAsync(ProjetoModel Projeto)
        {
            using (var con = new SqlConnection(this.ConnectionString))
            {
                try
                {
                    con.Open();
                    var query = "Update Projeto Set NomeProjeto = @Nome, DescricaoProjeto = @DescricaoProjeto WHERE IdProjeto = @IdProjeto";


                    using (SqlCommand command = new SqlCommand(query, con))
                    {
                        command.Parameters.AddWithValue("@Nome", Projeto.NomeProjeto);
                        command.Parameters.AddWithValue("@DescricaoProjeto", Projeto.DescricaoProjeto);
                        command.Parameters.AddWithValue("@IdProjeto", Projeto.IdProjeto);

                        int result = await command.ExecuteNonQueryAsync();
                    }
                }
                catch (Exception ex)
                {
                    return(false);
                }
                finally
                {
                    con.Close();
                }
            }

            return(true);
        }
Example #2
0
        public async Task <bool> InsertAsync(ProjetoModel Projeto)
        {
            using (var con = new SqlConnection(this.ConnectionString))
            {
                try
                {
                    con.Open();
                    var query = "SET DATEFORMAT DMY INSERT INTO Projeto Values (@Nome, @DescricaoProjeto, @Date)";


                    using (SqlCommand command = new SqlCommand(query, con))
                    {
                        command.Parameters.AddWithValue("@Nome", Projeto.NomeProjeto);
                        command.Parameters.AddWithValue("@DescricaoProjeto", Projeto.DescricaoProjeto);
                        command.Parameters.AddWithValue("@Date", DateTime.Now);

                        int result = await command.ExecuteNonQueryAsync();
                    }
                }
                catch (Exception ex)
                {
                    return(false);
                }
                finally
                {
                    con.Close();
                }

                return(true);
            }
        }