Exemplo n.º 1
0
        public async Task <ActionResult <DollarExchangeRate> > Put(
            [FromServices] DataContext context,
            int id,
            [FromBody] DollarExchangeRate model)
        {
            // Verifica se o ID informado é o mesmo do modelo
            if (id != model.Id)
            {
                return(NotFound(new { message = "Cotação não encontrada" }));
            }

            // Verifica se os dados são válidos
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                context.Entry <DollarExchangeRate>(model).State = EntityState.Modified;
                await context.SaveChangesAsync();

                return(model);
            }
            catch (DbUpdateConcurrencyException)
            {
                return(BadRequest(new { message = "Não foi possível atualizar a Cotação" }));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult <DollarExchangeRate> > Post(
            [FromServices] DataContext context,
            [FromBody] DollarExchangeRate model)
        {
            // Verifica se os dados são válidos
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                context.DollarExchangeRate.Add(model);
                await context.SaveChangesAsync();

                return(model);
            }
            catch (Exception)
            {
                return(BadRequest(new { message = "Não foi possível criar a Cotação" }));
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //-------Pattern Matching------------
            DollarExchangeRate dollar = new DollarExchangeRate()
            {
                DateExchangeRate = new DateTime(2017, 3, 24),
                CommercialValue  = 3.1083,
                TurismValue      = 3.2700
            };

            PatternMatching.Example(dollar);

            EuroExchangeRate euro = new EuroExchangeRate()
            {
                DateExchangeRate  = new DateTime(2017, 3, 24),
                ExchangeRateValue = 3.3695
            };

            PatternMatching.Example(euro);
            //-------------------------------------------



            //--------Exception Temperature--------
            ExceptionTemperature.Celsius = -30000;
            //------------------------------------


            //-------------OutVariables-------------
            OutVariables.Example1("07/03/2017");
            OutVariables.Example1("GenerateSomeError");
            OutVariables.Example2("07/03/2017");
            //------------------------------------------


            //------------Local Functions-------------
            string Inverse(string value)
            {
                return(new string(
                           value.ToCharArray().Reverse().ToArray()));
            }

            Console.WriteLine(Inverse("italo"));

            string Inverse2(string value) => new string(value.ToCharArray().Reverse().ToArray());

            Console.WriteLine(Inverse2("italo"));
            //------------------------------


            //-----------Binary Digits---------

            BinHex.YBin = 0b01011001; // 89
            BinHex.ZBin = 0B01011010; // 90
            BinHex.SumBin();          //179

            //--------------------------

            //-----------Expression Bodied Members------------
            ExpressionBodiedMembers example = new ExpressionBodiedMembers(@"C:\Temp\Some\Path");

            //-------------------------------------------------

            //---------------Digit Separator---------------
            BinHex.YBin = 0b01_01_10_01; // 01011001 (binário) = 89 (decimal)
            BinHex.ZBin = 0b01_01_10_01; // 01011001 (binário) = 89 (decimal)
            BinHex.SumBin();

            BinHex.YHex = 0X5_A; // 5A (hexadecimal) = 80 (decimal)

            BinHex.YInt    = 204_500_000;
            BinHex.ZDouble = 11_208.08;

            BinHex.PrintAll();
            //----------------------------------------------------

            //------------ref return---------------------
            var someNumber = 3;

            RefReturn.IncrementValue(ref someNumber);
            Console.WriteLine(someNumber);

            ref int someNumberReference = ref RefReturn.GetReference();