예제 #1
0
        public override long Create(Accident entity)
        {
            var connection = Dbconnection.Open();
            var command    = connection.CreateCommand();

            command.CommandText = "INSERT INTO public.accident (location, date, \"damage-amount\", person) VALUES (:location, :date, :dmg, :person)";
            command.Parameters.Add(new NpgsqlParameter("location", entity.Location));
            command.Parameters.Add(new NpgsqlParameter("date", NpgsqlDateTime.ToNpgsqlDateTime(entity.Date)));
            command.Parameters.Add(new NpgsqlParameter("dmg", entity.Damage_Amount));
            command.Parameters.Add(new NpgsqlParameter("person", entity.Person.Id));
            command.ExecuteNonQuery();

            command.CommandText = "SELECT \"record-number\" FROM public.accident WHERE location = :loc AND person = :pers";
            command.Parameters.Add(new NpgsqlParameter("loc", entity.Location));
            command.Parameters.Add(new NpgsqlParameter("pers", entity.Person.Id));
            var reader = command.ExecuteReader();

            long id = -1;

            if (reader.Read())
            {
                id = reader.GetInt64(0);
            }

            Dbconnection.Close();

            return(id);
        }
예제 #2
0
        public override void Update(Accident entity)
        {
            var connection = Dbconnection.Open();
            var command    = connection.CreateCommand();

            command.CommandText = "UPDATE public.accident SET location = :location, date = :date, " +
                                  "\"damage-amount\" = :dmg, person = :personid " +
                                  "WHERE \"record-number\" = :rec_id";
            command.Parameters.Add(new NpgsqlParameter("location", entity.Location));
            command.Parameters.Add(new NpgsqlParameter("date", NpgsqlDateTime.ToNpgsqlDateTime(entity.Date)));
            command.Parameters.Add(new NpgsqlParameter("dmg", entity.Damage_Amount));
            command.Parameters.Add(new NpgsqlParameter("personid", entity.Person.Id));
            command.Parameters.Add(new NpgsqlParameter("rec_id", entity.Record_Number));
            command.ExecuteNonQuery();

            Dbconnection.Close();
        }