예제 #1
0
        public async Task <AmigoResponse> Atualizar(long id, AmigoRequest request)
        {
            var amigo = await _context.Amigo.FirstOrDefaultAsync(x => x.Id == id);

            if (amigo == null)
            {
                _notification.AddNotification("Amigo", "Amigo não foi encontrado");
                return(null);
            }

            if (await _context.Amigo.AnyAsync(x => x.Apelido == request.Apelido && x.Id != id))
            {
                _notification.AddNotification("Amigo", "Amigo já cadastrado");
                return(null);
            }

            amigo.Atualizar(request.Apelido, request.Telefone);

            _entityValidator.Validate(new Entity[] { amigo });

            if (_notification.HasNotifications)
            {
                return(null);
            }

            await _context.SaveChangesAsync();

            return(_mapper.Map <AmigoResponse>(amigo));
        }
        public async Task <AmigoResponse> InserirAsync(AmigoRequest amigoRequest)
        {
            var amigo = _mapper.Map <Amigo>(amigoRequest);

            ValidarAmigo(amigo);

            return(await Task.FromResult(_mapper.Map <AmigoResponse>(_amigoRepositorio.Inserir(amigo))));
        }
        public async Task <AmigoResponse> AtualizarAsync(AmigoRequest amigoRequest)
        {
            var ExisteAmigo = _amigoRepositorio.Existe(amigoRequest.Id);

            if (!ExisteAmigo)
            {
                throw new NegocioException("Amigo Não Encontrado!");
            }

            var amigo = _mapper.Map <Amigo>(amigoRequest);

            ValidarAmigo(amigo);

            return(await Task.FromResult(_mapper.Map <AmigoResponse>(_amigoRepositorio.Atualizar(amigo))));
        }
예제 #4
0
        public async Task <AmigoResponse> Inserir(AmigoRequest request)
        {
            if (await _context.Amigo.AnyAsync(x => x.Apelido == request.Apelido))
            {
                _notification.AddNotification("Amigo", "Amigo já cadastrado");
                return(null);
            }

            var amigo = new Amigo(request.Apelido, request.Telefone);

            _entityValidator.Validate(new Entity[] { amigo });

            if (_notification.HasNotifications)
            {
                return(null);
            }

            await _context.Amigo.AddAsync(amigo);

            await _context.SaveChangesAsync();

            return(_mapper.Map <AmigoResponse>(amigo));
        }
예제 #5
0
        public async Task <ActionResult <AmigoResponse> > Editar([FromBody] AmigoRequest amigo)
        {
            var AmigoResponse = await _amigoServico.AtualizarAsync(amigo).ConfigureAwait(false);

            return(Ok(AmigoResponse));
        }
예제 #6
0
 public ActionResult Put([FromRoute] Guid id, [FromBody] AmigoRequest update)
 {
     _Service.Update(id, update.Nome, update.Sobrenome, update.DtAniversario, update.Email, update.Telefone, update.Urlfoto);
     return(Ok(update));
 }
예제 #7
0
 public ActionResult Autor([FromBody] AmigoRequest create)
 {
     _Service.Create(create.Nome, create.Sobrenome, create.DtAniversario, create.Email, create.Telefone, create.Urlfoto);
     return(Created("api/[controller]", create));
 }