public async Task <ContatoFuncionario> CreateAsync(ContatoFuncionario contatoFun)
        {
            this._logger.LogDebug("Starting CreateAsync");

            var existContatoEmail = await _sqlService.ExistsAsync(ContatoFuncionarioQuery.EXIST_CONTATOFUN_EMAIL, new
            {
                EMAIL = contatoFun.Email
            });

            var existContatoTelefone = await _sqlService.ExistsAsync(ContatoFuncionarioQuery.EXIST_CONTATOFUN_TELEFONE, new
            {
                TELEFONE = contatoFun.Email
            });

            if (existContatoEmail && existContatoTelefone)
            {
                this._logger.LogDebug("Contato already exists, triggering 400");

                this._validationService.Throw("Contato", "There is already another funcionario with that Email or Telefone", contatoFun, Validation.ContatoExists);
            }

            this._logger.LogDebug("Inserting new Contato");

            contatoFun.ContatoFunId = await _sqlService.CreateAsync(ContatoFuncionarioQuery.INSERT, new
            {
                FUNCIONARIOID = contatoFun.FuncionarioId,
                EMAIL         = contatoFun.Email,
                TELEFONE      = contatoFun.Telefone
            });

            this._logger.LogDebug("Ending CreateAsync");

            return(contatoFun);
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Put(
            [SwaggerParameter("contatoFun's Id")] int contatoFunId,
            [FromBody] ContatoFuncionario contatoFun)
        {
            var edited = await _contatoFuncionarioService.UpdateAsync(contatoFunId, contatoFun);

            return(Ok(edited));
        }
        public async Task <ContatoFuncionario> UpdateAsync(int id, ContatoFuncionario contatoFun)
        {
            this._logger.LogDebug("Starting UpdateAsync");

            var oldContato = await GetAsync(id);

            var existContatoEmail = await _sqlService.ExistsAsync(ContatoFuncionarioQuery.EXIST_CONTATOFUN_EMAIL, new
            {
                EMAIL = contatoFun.Email
            });

            var existContatoTelefone = await _sqlService.ExistsAsync(ContatoFuncionarioQuery.EXIST_CONTATOFUN_TELEFONE, new
            {
                TELEFONE = contatoFun.Telefone
            });

            if (existContatoEmail && existContatoTelefone)
            {
                this._logger.LogDebug("Contato already exists, triggering 400");

                this._validationService.Throw("Contato", "There is already another funcionario with that Email or Telefone", contatoFun, Validation.ContatoExists);
            }

            var existContato = await _sqlService.ExistsAsync(ContatoFuncionarioQuery.EXIST_CONTATOFUN_ID, new
            {
                Id = oldContato.ContatoFunId
            });

            this._logger.LogDebug("Checking if that contato already exists");

            if (!existContato)
            {
                this._logger.LogDebug("Contato already exists, triggering 400");

                this._validationService.Throw("Contato", "There is already another funcionario with that id", contatoFun.ContatoFunId, Validation.ContatoNotExists);
            }

            this._logger.LogDebug("Updating contato");

            await _sqlService.ExecuteAsync(ContatoFuncionarioQuery.UPDATE, new
            {
                Id            = id,
                FUNCIONARIOID = contatoFun.FuncionarioId,
                EMAIL         = contatoFun.Email,
                TELEFONE      = contatoFun.Telefone
            });

            contatoFun.ContatoFunId = oldContato.ContatoFunId;

            this._logger.LogDebug("Ending UpdateAsync");

            return(contatoFun);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Post([FromBody] ContatoFuncionario contatoFun)
        {
            var created = await _contatoFuncionarioService.CreateAsync(contatoFun);

            return(CreatedAtAction(nameof(Post), new { id = contatoFun.ContatoFunId }, created));
        }