Exemplo n.º 1
0
        public static void ExercicioF(string cs, string isin, decimal valor, DateTime date)
        {
            try
            {
                using (var ts = new TransactionScope())
                {
                    IMapperTriplo  triplosMapper = new MapperTriplo();
                    IMapperRegisto registoMap    = new MapperRegisto();

                    Triplo triplo = new Triplo()
                    {
                        Identificacao = isin,
                        Dia           = date,
                        Valor         = valor
                    };

                    RegistoKey key = new RegistoKey(isin, date);

                    triplosMapper.Create(triplo);

                    Console.WriteLine("\nChamada ao stored procedure:\n");

                    P_atualizaValorFunc(new SqlConnection(cs));

                    Console.WriteLine("Registo depois da chamada ao stored procedure:");
                    Console.WriteLine(registoMap.Read(key).ToString());

                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Excepção apanhada : " + ex.Message);
            }
        }
Exemplo n.º 2
0
        public static void Exercicio1B_Update(string isin, DateTime date, int val)
        {
            try
            {
                using (var ts = new TransactionScope())
                {
                    RegistoKey            key                  = new RegistoKey(isin, date.Date);
                    IMapperRegisto        mapperRegisto        = new MapperRegisto();
                    IMapperValoresMercado mapperValoresMercado = new MapperValoresMercado();
                    IMapperInstrumento    mapperInstrumento    = new MapperInstrumento();

                    Instrumento instrumento = mapperInstrumento.Read(isin);

                    Console.WriteLine("Informação de valores de mercado antes do update:");
                    Console.WriteLine(mapperValoresMercado.Read(new ValoresMercadoKey(instrumento.CodigoMercado, date)).ToString());

                    //Update
                    Registo registo = mapperRegisto.Read(key);
                    registo.ValorAbertura = val;
                    mapperRegisto.Update(registo);
                    Console.WriteLine("\nUpdate\n");

                    Console.WriteLine("Informação de valores de mercado depois do update:");
                    Console.WriteLine(mapperValoresMercado.Read(new ValoresMercadoKey(instrumento.CodigoMercado, date)).ToString() + "\n");

                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Excepção apanhada : " + ex.Message);
            }
        }