Пример #1
0
 public async Task <Evento> AddEvento(Evento model)
 {
     try
     {
         _geralpersist.Add <Evento>(model);
         if (await _geralpersist.SaveChangesAsync())
         {
             return(await _eventoPersist.GetEventoByIdAsync(model.Id));
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #2
0
        public async Task <Evento> AddEvento(Evento model)
        {
            try
            {
                _geralPersist.Add <Evento>(model);

                if (await _geralPersist.SaveChangesAsync())                           //SaveChangesAsync() == true -> Faz o IF
                {
                    return(await _eventoPersist.GetEventoByIdAsync(model.Id, false)); //Se foi adicionado, retorno o ID do evento(model) após a adição
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #3
0
        public async Task <EventoDto> AddEventos(EventoDto model)
        {
            try
            {
                var evento = _mapper.Map <Evento>(model);//LE-SE: Vai pegar o "model" que é um "Dto", vai mapear ele para um "Evento" e atribuir a variável "var evento".
                _geralPersist.Add <Evento>(evento);
                if (await _geralPersist.SaveChangesAsync())
                {
                    var eventoRetorno = await _eventoPersist.GetEventoByIdAsync(evento.Id, false);

                    //Faz o mapeamento ao contrário, adicionando o ".ReverseMap()" em ProEventosProfile, fazendo o invérso.
                    return(_mapper.Map <EventoDto>(eventoRetorno));// LE-SE: Mapeado o evento de retorno para o meu Dto.
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #4
0
        public async Task <EventoDto> AddEvento(EventoDto model)
        {
            try
            {
                var evento = _mapper.Map <Evento>(model);

                _geralPersist.Add <Evento>(evento);
                if (await _geralPersist.SaveChangesAsync())
                {
                    var eventoRetorno = await _eventoPersist.GetEventoByIdAsync(evento.Id, false);

                    return(_mapper.Map <EventoDto>(eventoRetorno));
                }
                return(null);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }
Пример #5
0
        public async Task <Evento> AddEventos(Evento model)
        {
            try
            {
                //adiciono a model do método para o geralPersist
                _geralPersist.Add <Evento>(model);

                //se a model for salva
                if (await _geralPersist.SaveChangesAsync())
                {
                    //retornar o evento pelo id da model
                    return(await _eventoPersist.GetEventoByIdAsync(model.Id, false));
                }
                //se não, retorna nulo
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }