예제 #1
0
        public IActionResult Cadastrar([FromBody] SedeDomain sede)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_sedeRepository.SedeExiste(sede.Nome))
                    {
                        return(BadRequest("Nome já cadastrado"));
                    }

                    _sedeRepository.Inserir(sede);
                }

                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                if (errors.Any())
                {
                    return(BadRequest(errors));
                }
                else
                {
                    return(Ok(sede));
                }
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
예제 #2
0
        public IActionResult Atualizar([FromBody] SedeDomain sede, int id)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    sede.SedeId = id;
                    _sedeRepository.Atualizar(sede);
                }
                var errors = ModelState.Select(x => x.Value.Errors)
                             .Where(y => y.Count > 0)
                             .ToList();

                if (errors.Any())
                {
                    return(BadRequest(errors));
                }
                else
                {
                    return(Ok(sede));
                }
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }