Exemple #1
0
        public string Create(ContatoCreateRequest request)
        {
            Domain.Contato entity = new Domain.Contato(request.Nome, request.Canal, request.Valor, request.Observacao);
            contatoService.Create(entity);

            return(entity.Id.ToString());
        }
Exemple #2
0
        public List <KeyValuePair <string, string> > Validar(ContatoCreateRequest request)
        {
            List <KeyValuePair <string, string> > validations = new List <KeyValuePair <string, string> >();

            if (String.IsNullOrEmpty(request.Canal))
            {
                validations.Add(new KeyValuePair <string, string>("Canal", "Campo é obrigatório."));
            }
            if (String.IsNullOrEmpty(request.Nome))
            {
                validations.Add(new KeyValuePair <string, string>("Nome", "Campo é obrigatório."));
            }
            if (String.IsNullOrEmpty(request.Valor))
            {
                validations.Add(new KeyValuePair <string, string>("Valor", "Campo é obrigatório."));
            }

            return(validations);
        }
Exemple #3
0
        public IActionResult Create([FromBody] ContatoCreateRequest request)
        {
            string id = string.Empty;

            try
            {
                var validations = Validar(request);
                if (validations.Count > 0)
                {
                    return(BadRequest(validations.Select(v => new { atributo = v.Key, mensagem = v.Value })));
                }

                id = contatoApplicationService.Create(request);

                return(Created("", id));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }