예제 #1
0
 public void AtualizarServico(ServicoDto servicoDto)
 {
     Nome              = servicoDto.Nome;
     Valor             = servicoDto.Valor;
     Duracao           = servicoDto.Duracao;
     EstabelecimentoId = servicoDto.EstabelecimentoId;
 }
예제 #2
0
        public async Task <ActionResult <ServicoDto> > GetByHumanCode(ServicoDto dto)
        {
            try
            {
                var myUsername = User.Identity.Name;
                if (ZZApiMain.VerifyUserAuthorize(myUsername))
                {
                    if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn))
                    {
                        var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Cmd = ServerCommands.GetById, EntityId = dto.Id, Tela = Tela, Json = await SerializerAsync.SerializeJson(dto) });

                        var responseCommand = await myConn.Zz.GetApiWaitCommand(myId);

                        if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk))
                        {
                            return(await SerializerAsync.DeserializeJson <ServicoDto>(responseCommand.Json));
                        }
                    }
                }
                return(NotFound());
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
                return(NotFound());
            }
        }
예제 #3
0
        public async Task <IActionResult> PutServico(int id, ServicoDto servico)
        {
            var servico2 = new Servico
            {
                Descricao     = servico.Descricao,
                FuncionarioId = int.Parse(servico.FuncionarioId),
                ClienteId     = int.Parse(servico.ClienteId)
            };

            if (id != servico2.Id)
            {
                return(BadRequest());
            }

            _context.Entry(servico2).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ServicoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #4
0
        public async Task <ServicoDto> Salvar(ServicoDto servicoDto)
        {
            Servico servico = new(servicoDto.Id, servicoDto.Codigo, servicoDto.Nome, servicoDto.Descricao, servicoDto.Valor, servicoDto.Alteracao, servicoDto.Ativo);
            Servico resultado;

            if (servicoDto.Id.Equals(0))
            {
                resultado = await _repositorio.Adicionar(servico);

                if (resultado is null)
                {
                    throw new Exception("Erro ao cadastrar, contate o administrador do sistema.");
                }

                servicoDto.Id     = resultado.Id;
                servicoDto.Codigo = resultado.Codigo;

                return(servicoDto);
            }
            else
            {
                resultado = await _repositorio.Atualizar(servico);

                if (resultado is null)
                {
                    throw new Exception("Erro ao atualizar, contate o administrador do sistema.");
                }

                return(servicoDto);
            }
        }
예제 #5
0
        public async Task <IActionResult> Put(int ServicoId, ServicoDto model)
        {
            try
            {
                var servico = await _repo.GetAllServicoAsyncById(ServicoId);

                if (servico == null)
                {
                    return(NotFound());
                }

                _mapper.Map(model, servico);

                _repo.Update(servico);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/servico/{model.Id}", _mapper.Map <ServicoDto>(servico)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError,
                                       $"Banco de dados falhou: {ex.Message}"));
            }

            return(BadRequest());
        }
예제 #6
0
        public void TestaCreateComInformacoesObrigatoriasNulas()
        {
            var servicoDto = new ServicoDto();
            var retorno    = _servicoService.Create(servicoDto);

            Assert.IsTrue(retorno.Result.StatusCode == (int)EStatusCode.ERRO_VALIDACAO);
            Assert.IsTrue(retorno.Result.Errors.Contains("Informe o nome!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Informe o valor!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Informe a duracao!"));
            Assert.IsTrue(retorno.Result.Errors.Contains("Nenhum estabelecimento vinculado!"));

            Assert.IsTrue(retorno.Result.Errors.Count == 4);
        }
예제 #7
0
        public async Task <ActionResult <Servico> > PostServico(ServicoDto servico)
        {
            var servico2 = new Servico
            {
                Descricao     = servico.Descricao,
                FuncionarioId = int.Parse(servico.FuncionarioId),
                ClienteId     = int.Parse(servico.ClienteId)
            };

            _context.Servico.Add(servico2);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetServico", new { id = servico2.Id }, servico2));
        }
예제 #8
0
        public async Task <ResultDto <bool> > Update(ServicoDto servicoDto)
        {
            var servicoDtoValidate = new ServicoDtoValidate(servicoDto);

            if (!servicoDtoValidate.Validate())
            {
                return(await Task.FromResult(ResultDto <bool> .Validation(servicoDtoValidate.Mensagens)));
            }

            var servico = await _servicoRepository.ObterPorId(servicoDto.ServicoId);

            servico.AtualizarServico(servicoDto);
            await _servicoRepository.Update(servico);

            return(await Task.FromResult(ResultDto <bool> .Success(true)));
        }
예제 #9
0
        public async Task <ResultDto <ServicoDto> > Create(ServicoDto servicoDto)
        {
            var servicoDtoValidate = new ServicoDtoValidate(servicoDto);

            if (!servicoDtoValidate.Validate())
            {
                return(await Task.FromResult(ResultDto <ServicoDto> .Validation(servicoDtoValidate.Mensagens)));
            }

            var servico = _mapper.Map <Servico>(servicoDto);

            servico.SituacaoId   = (int)ESituacao.ATIVO;
            servico.DataCadastro = DateTime.Now;
            await _servicoRepository.Create(servico);

            return(await Task.FromResult(ResultDto <ServicoDto> .Success(_mapper.Map <ServicoDto>(servico))));
        }
예제 #10
0
        public JsonResult RecuperarInfoServico(int codigoServico)
        {
            ServicoDto servicoSelecionado = _servicoService
                                            .List()
                                            .Where(x => x.Id == codigoServico)
                                            .Select(y => new ServicoDto()
            {
                Descricao = y.Descricao,
                DescricaoPeriodicidade = "",
                Periodicidade          = y.Periodicidade,
                QuantidadeSessoes      = y.QuantidadeSessoes,
                ValorServico           = y.ValorServico
            }).FirstOrDefault();

            return(Json(servicoSelecionado, JsonRequestBehavior.AllowGet));

            ;
        }
예제 #11
0
        public override EntityDto ConvertDto()
        {
            try
            {
                var dto = new ServicoDto
                {
                    Id            = Id, DescricaoCompleta = DescricaoCompleta, Codigo = Codigo, DescricaoResumida = DescricaoResumida, Observacoes = Observacoes,
                    TipoServicoId = TipoServicoId, UnidadeMedidaId = UnidadeMedidaId, CentroCustoId = CentroCustoId, ControlaEstoque = ControlaEstoque
                };

                return(dto);
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
                return(null);
            }
        }
예제 #12
0
        public async Task <IActionResult> Post(ServicoDto model)
        {
            try
            {
                var servico = _mapper.Map <Servico>(model);

                _repo.Add(servico);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/servico/{model.Id}", _mapper.Map <ServicoDto>(servico)));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError,
                                       $"Banco de dados falhou : {ex.Message}"));
            }

            return(BadRequest());
        }
예제 #13
0
 public async Task <ResultDto <bool> > Put(int id, [FromBody] ServicoDto servicoDto)
 {
     return(await _servicoService.Update(servicoDto));
 }
예제 #14
0
 public async Task <ResultDto <ServicoDto> > Post([FromBody] ServicoDto servicoDto)
 {
     return(await _servicoService.Create(servicoDto));
 }
예제 #15
0
 public ServicoDtoValidate(ServicoDto servicoDto)
 {
     _servicoDto = servicoDto;
     Mensagens   = new List <string>();
 }
예제 #16
0
        public IActionResult EnviaEmail(string destinatario, ServicoDto model)
        {
            try
            {
                var message = new MimeMessage();
                message.From.Add(new MailboxAddress("SGCOS", "*****@*****.**"));
                message.To.Add(new MailboxAddress("SGCOS", destinatario));
                message.Subject = "Ordem de serviço:" + model.NrOrdem;

                var data = Convert.ToDateTime(model.DtAtendimento);



                var bodyBuilder = new BodyBuilder();
                bodyBuilder.HtmlBody = "<h1>Sua nova ordem de serviço.</h1>" +
                                       "<table>" +
                                       "<tbody>" +
                                       "<tr>" +
                                       "<td><b>Nr Ordem :</b></td>" +
                                       $"<td>{model.NrOrdem}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Data de Atendimento :</b></td>" +
                                       $"<td>{String.Format("{0:dd/MM/yyyy}",data)}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Dias de Garantia :</b></td>" +
                                       $"<td>{model.QtdDiasGarantia}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Defeito :</b></td>" +
                                       $"<td>{model.Defeito}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Serviços Executados :</b></td>" +
                                       $"<td>{model.ServicosExecutados}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Peças Substituidas :</b></td>" +
                                       $"<td>{model.PecasSubstituidas}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Observações :</b></td>" +
                                       $"<td>{model.Observacao}</td>" +
                                       "</tr>" +
                                       "<tr>" +
                                       "<td><b>Valor :</b></td>" +
                                       $"<td>{String.Format("{0:C}",model.ValorServico)}</td>" +
                                       "</tr>" +
                                       "</tbody>" +
                                       "</table>";

                message.Body = bodyBuilder.ToMessageBody();

                using (var client = new SmtpClient()){
                    client.Connect("email-ssl.com.br", 587, false);
                    client.Authenticate("*****@*****.**", "@Simmasa0603");
                    client.Send(message);
                    client.Disconnect(true);
                }

                return(Ok());
            }
            catch (System.Exception)
            {
                throw;
            }
        }