public ICommandResult Handle(NovoProgramaCommand command)
        {
            RemoveAllNotifications();
            var tempo    = new Tempo(command.Tempo);
            var potencia = new Potencia(command.Potencia);
            var caracter = new Caracter(command.Caracter);

            var aquecimento = new Aquecimento(tempo, potencia, caracter, command.Chave);
            var programa    = new Programa(command.Nome, command.Instrucoes, aquecimento);

            AddNotifications(tempo.Notifications);
            AddNotifications(potencia.Notifications);
            AddNotifications(caracter.Notifications);

            var existePrograma = _repositorio.Get(programa.Nome) != null;

            if (existePrograma)
            {
                AddNotification("Nome", "Ja existe um programa com o mesmo nome informado");
            }

            if (Invalid)
            {
                return(new NovoProgramaResult(false, "Por favor corrija os campos abaixo", Notifications));
            }

            _repositorio.Novo(programa);

            return(new NovoProgramaResult(true, "Novo programa cadastrado com sucesso", new { Nome = programa.Nome }));
        }
Example #2
0
        protected bool Validacoes(Aquecimento aquecimento)
        {
            int potencia = 0;
            int tempo    = 0;

            aquecimento.Produto = txtProduto.Text;

            try
            {
                tempo = Convert.ToInt32(txtTempo.Text);
                if (tempo < 1)
                {
                    lblTempo.Visible = true;
                    lblTempo.Text    = "O tempo não pode ser menor que 1 segundo.";
                }
                if (tempo > 120)
                {
                    lblTempo.Visible = true;
                    lblTempo.Text    = "O tempo não pode ser maior que 120 segundos.";
                    return(false);
                }
            }
            catch (Exception e)
            {
                lblTempo.Visible = true;
                return(false);
            }

            try
            {
                potencia = Convert.ToInt32(txtPotencia.Text);

                if (potencia > 10)
                {
                    lblPotencia.Text    = "Potencia não pode exceder o valor 10.";
                    lblPotencia.Visible = true;
                    return(false);
                }

                if (potencia < 1)
                {
                    lblPotencia.Text    = "Potencia não pode ser menor que o 1.";
                    lblPotencia.Visible = true;
                    return(false);
                }
            }
            catch (Exception e)
            {
                lblPotencia.Visible = true;
                return(false);
            }

            aquecimento.Potencia = potencia;
            aquecimento.Tempo    = tempo;

            return(true);
        }
Example #3
0
 public Aquecimento InicioRapido(Aquecimento aquecimento)
 {
     if (string.IsNullOrEmpty(aquecimento.Alimento))
     {
         throw new StringVaziaException("Não é possivel iniciar o aquecimento sem informar o Alimento");
     }
     aquecimento.AquecimentoRapido(); //adiciona parametros de aquecimento rapido nos atributos de potencia e tempo
     AqueceAlimento(aquecimento);
     return(aquecimento);
 }
 public IActionResult InicioRapido(Aquecimento aquecimento)
 {
     try
     {
         var obj = _aquecimentoService.InicioRapido(aquecimento);
         return(View(nameof(Iniciar), obj));
     }
     catch (ApplicationException e)
     {
         return(RedirectToAction(nameof(Error), new { message = e.Message }));
     }
 }
        protected override string RealizaAquecimento(string campoString, Aquecimento aquecimento)
        {
            var campoNovo = new StringBuilder(campoString);

            for (var i = 1; i <= aquecimento.Tempo.Horario.TotalSeconds; i++)
            {
                for (var j = 1; j <= aquecimento.Potencia.Forca; j++)
                {
                    campoNovo.Append(aquecimento.Caracter.Valor);
                }
            }
            return(campoNovo.ToString());
        }
Example #6
0
        protected void ProcessoAquecimento(Aquecimento aquecimento)
        {
            Session["timer"]    = aquecimento.Tempo;
            Session["potencia"] = aquecimento.Potencia;

            string arquivo = txtProduto.Text;

            if (File.Exists(arquivo))
            {
                Session["produto"] = txtProduto.Text;
            }
            tmrTimer.Enabled = true;
        }
Example #7
0
        protected void btnRapidoAquecimento_Click(object sender, EventArgs e)
        {
            Aquecimento aquecimento = new Aquecimento();

            this.Inicializar();
            txtPotencia.Text = "8";
            txtTempo.Text    = "30";

            if (Validacoes(aquecimento))
            {
                this.ProcessoAquecimento(aquecimento);
            }
        }
Example #8
0
 protected override string RealizaAquecimento(string campoString, Aquecimento aquecimento)
 {
     using (var x = File.AppendText(campoString))
     {
         for (var i = 1; i <= aquecimento.Tempo.Horario.TotalSeconds; i++)
         {
             for (var j = 1; j <= aquecimento.Potencia.Forca; j++)
             {
                 x.Write(aquecimento.Caracter.Valor);
             }
             x.WriteLine();
         }
     }
     return("Arquivo gravado com sucesso");
 }
Example #9
0
        public Aquecimento AqueceAlimento(Aquecimento aquecimento)
        {
            var minutos  = aquecimento.Tempo.Hours;
            var segundos = aquecimento.Tempo.Minutes;
            var potencia = aquecimento.Potencia;

            if ((minutos > 2) || (segundos < 1 && minutos < 1) || (minutos >= 2 && segundos > 0) || (minutos == 0 && segundos == 0))
            {
                throw new TempoException("O tempo deve estar entre 2 Minutos(02:00) e 1 Segundo (00:01)");
            }
            if (potencia < 1 || potencia > 10)
            {
                throw new PotenciaException("Potencia Minima permitida: 1, Maxima permitida : 10");
            }
            return(aquecimento);
        }
 public IActionResult Aquecer(Aquecimento aquecimento)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var obj = _aquecimentoService.AqueceAlimento(aquecimento);
             return(View(nameof(Iniciar), obj));
         }
         catch (TempoException e)
         {
             return(RedirectToAction(nameof(Error), new { message = e.Message }));
         }
         catch (PotenciaException e)
         {
             return(RedirectToAction(nameof(Error), new { message = e.Message }));
         }
     }
     return(RedirectToAction("Index", "Home"));
 }
Example #11
0
        public ICommandResult Handle(NovoProgramaCommand command)
        {
            var tempo    = new Tempo(command.Tempo);
            var potencia = new Potencia(command.Potencia);
            var caracter = new Caracter(command.Caracter);

            var aquecimento = new Aquecimento(tempo, potencia, caracter, command.Chave);
            var programa    = new Programa(command.Nome, command.Instrucoes, aquecimento);

            AddNotifications(tempo.Notifications);
            AddNotifications(potencia.Notifications);
            AddNotifications(caracter.Notifications);

            if (Invalid)
            {
                return(new NovoProgramaResult(false, "Por favor corrija os campos abaixo", Notifications));
            }

            _repositorio.Novo(programa);

            return(new NovoProgramaResult(true, "Novo programa cadastrado com sucesso", new { Nome = programa.Nome }));
        }
Example #12
0
        public ICommandResult Handle(AquecimentoCommand command)
        {
            var tempo    = new Tempo(command.Tempo);
            var potencia = new Potencia(command.Potencia);
            var caracter = new Caracter(command.Caracter);

            var aquecimento = new Aquecimento(tempo, potencia, caracter, command.Chave);

            AddNotifications(tempo.Notifications);
            AddNotifications(potencia.Notifications);
            AddNotifications(caracter.Notifications);

            VerificaSeAChaveEstaCorreta(command.CampoString, aquecimento.Chave);

            if (Invalid)
            {
                return(new AquecimentoResult(false, "Por favor corrija os campos abaixo", Notifications));
            }

            var retorno = RealizaAquecimento(command.CampoString, aquecimento);

            return(new AquecimentoResult(true, "Aquecimento realizado com sucesso", retorno));
        }
Example #13
0
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            if (ValidacoesCadastro(aquecimento))
            {
                ProdutosProntos produto = new ProdutosProntos();
                Aquecimento     aqueci  = new Aquecimento();

                produto.Instrucoes  = txtInstCad.Text;
                produto.NomeProduto = txtProdCad.Text;
                produto.Aquecer     = txtCarCad.Text;
                aqueci.Potencia     = Convert.ToInt32(txtPotCad.Text);
                aqueci.Tempo        = Convert.ToInt32(txtTempoCad.Text);

                ProdutosProntos = ListProdutosProntos.InsereRetornaLista(produto, aqueci);

                txtInstCad.Text  = "";
                txtProdCad.Text  = "";
                txtCarCad.Text   = "";
                txtPotCad.Text   = "";
                txtTempoCad.Text = "";

                preencheComboProdutosProntos(); //Atualiza os itens da lista
            }
        }
Example #14
0
 protected abstract string RealizaAquecimento(string campoString, Aquecimento aquecimento);
 public IActionResult Iniciar(Aquecimento obj) //abre a view mostrando o aquecimento
 {
     return(View(obj));
 }
Example #16
0
 public Programa(string nome, string instrucoes, Aquecimento aquecimento)
 {
     Nome        = nome;
     Instrucoes  = instrucoes;
     Aquecimento = aquecimento;
 }