コード例 #1
0
        public async Task <user> UpdateUser(int userId, user model)
        {
            try
            {
                var LEuser = await _userPresist.GetAllUserByIdAsync(userId);

                if (LEuser == null)
                {
                    return(null);
                }
                //atenção aqui
                model.Id = LEuser.Id;

                FGeralPersist.Update <user>(model);
                if (await FGeralPersist.SaveChangesAsync())
                {
                    return(await _userPresist.GetAllUserByIdAsync(model.Id));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #2
0
        public async Task <Fornecedor> AlterarSenha(int id, string senha)
        {
            try
            {
                var LEuser = await _FornecedorPresist.GetAllFornecedorByIdAsync(id);

                if (LEuser == null)
                {
                    return(null);
                }
                //atenção aqui
                LEuser.Senha = senha;

                FGeralPersist.Update <Fornecedor>(LEuser);
                if (await FGeralPersist.SaveChangesAsync())
                {
                    return(await _FornecedorPresist.GetAllFornecedorByIdAsync(LEuser.Id));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #3
0
        public async Task <Pedido> AprovaPedidoAsync(int id, AprovarPedidoDTO model)
        {
            try
            {
                var pedido = await _pedidoPresist.GetPedidoByIdAsync(id);

                if (pedido == null)
                {
                    return(null);
                }

                pedido.AprovadorId = model.AprovadorId;
                var data = model.DataAprovacao.ToString("dd/MM/yyyy");
                pedido.DataAprovacao      = data;
                pedido.StatusAprov        = model.StatusAprov;
                pedido.ObservacaoRejeicao = model.ObservacaoRejeicao;

                await GerarRankingAsync(pedido.cotacaoId);


                FGeralPersist.Update <Pedido>(pedido);
                if (await FGeralPersist.SaveChangesAsync())
                {
                    await FGeralPersist.SaveChangesAsync();

                    return(await _pedidoPresist.GetPedidoByIdAsync(id));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #4
0
        public async Task <Solicitacao> AprovaSolicitacaoAsync(int id, AprovaSolicitacaoDTO model)
        {
            try
            {
                var LESolicitacao = await _SolicitacaoPresist.GetAllSolicitacaoByIdsemProdAsync(id);

                if (LESolicitacao == null)
                {
                    return(null);
                }

                solicitacao = LESolicitacao;
                var data = model.DataAprovacao.ToString("dd/MM/yyyy");;
                solicitacao.DataAprovacao      = data;
                solicitacao.IdAprovador        = model.IdAprovador;
                solicitacao.StatusAprovacao    = model.StatusAprovacao;
                solicitacao.ObservacaoRejeicao = model.ObservacaoRejeicao;

                FGeralPersist.Update <Solicitacao>(solicitacao);
                if (await FGeralPersist.SaveChangesAsync())
                {
                    return(await _SolicitacaoPresist.GetAllSolicitacaoByIdAsync(LESolicitacao.Id));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #5
0
ファイル: EventoService.cs プロジェクト: srozisca/ProEventos
        public async Task <Evento> UpdateEvento(int eventoId, Evento model)
        {
            try
            {
                var evento = await _eventoPersist.GetEventoByIdAsync(eventoId, false);

                if (evento == null)
                {
                    return(null);
                }

                //se alguém for encontrado...
                model.Id = eventoId;

                _geralPersist.Update(model);
                if (await _geralPersist.SaveChangesAsync())
                {
                    //retornar o evento pelo id da model
                    return(await _eventoPersist.GetEventoByIdAsync(model.Id, false));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #6
0
ファイル: EventoService.cs プロジェクト: vsandrade/ProEventos
        public async Task <EventoDto> UpdateEvento(int userId, int eventoId, EventoDto model)
        {
            try
            {
                var evento = await _eventoPersist.GetEventoByIdAsync(userId, eventoId, false);

                if (evento == null)
                {
                    return(null);
                }

                model.Id     = evento.Id;
                model.UserId = userId;

                _mapper.Map(model, evento);

                _geralPersist.Update <Evento>(evento);

                if (await _geralPersist.SaveChangesAsync())
                {
                    var eventoRetorno = await _eventoPersist.GetEventoByIdAsync(userId, evento.Id, false);

                    return(_mapper.Map <EventoDto>(eventoRetorno));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #7
0
        public async Task <Evento> UpdateEvento(int eventoId, Evento model)
        {
            try
            {
                var evento = await _eventoPersist.GetEventoByIdAsync(eventoId, false);

                if (evento == null)
                {
                    return(null);
                }

                model.Id = evento.Id;

                _geralPercist.Update(model);
                if (await _geralPercist.SaveChangesAsync())
                {
                    return(await _eventoPersist.GetEventoByIdAsync(model.Id, false));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #8
0
        public async Task <Loja> UpdateLoja(int lojaId, Loja model)
        {
            try
            {
                var loja = await _lojaPersist.GetLojaByIdAsync(lojaId);

                if (loja == null)
                {
                    return(null);
                }

                model.Id = loja.Id;

                _geralPersist.Update(model);

                if (await _geralPersist.SaveChangesAsync())
                {
                    return(await _lojaPersist.GetLojaByIdAsync(model.Id));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #9
0
        public async Task <EventoDto> UpdateEventos(int eventoId, EventoDto model)
        {
            try
            {
                var evento = await _eventoPersist.GetEventoByIdAsync(eventoId, false);

                if (evento == null)
                {
                    return(null);
                }

                model.Id = evento.Id;
                _mapper.Map(model, evento);            //Dto será mapeado para Evento.
                _geralPersist.Update <Evento>(evento); // ...e o Update recebe um objeto do tipo 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);
            }
        }
コード例 #10
0
        public async Task <Evento> UpdateEvento(int eventoId, Evento model)
        {
            try
            {
                var evento = await _eventoPersist.GetEventoByIdAsync(eventoId, false);

                if (evento == null)
                {
                    return(null);
                }

                model.Id = evento.Id;

                _geralPersist.Update(model);

                if (await _geralPersist.SaveChangesAsync())                           //SaveChangesAsync() == true -> Faz o IF
                {
                    return(await _eventoPersist.GetEventoByIdAsync(model.Id, false)); //Se foi atualizado, retorno o ID do evento(model) após a atualização
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #11
0
        public async Task <Evento> UpdateEvento(int eventoId, Evento model)
        {
            try
            {
                var evento = await _eventoPersist.GetEventoByIdAsync(eventoId);

                if (evento == null)
                {
                    return(null);
                }

                // Caso não venha preenchimento no parâmetro model
                model.Id = evento.Id;

                _geralPersist.Update <Evento>(model);
                if (await _geralPersist.SaveChangesAsync())
                {
                    return(await _eventoPersist.GetEventoByIdAsync(model.Id, false));
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
コード例 #12
0
        public async Task <Info> Update(Info model)
        {
            try
            {
                var oldResult = await _geralPersist.GetInfo();

                model.UpdatedAt = DateTime.Now;
                _geralPersist.Update <Info>(model);
                if (await _geralPersist.SaveChangesAsync())
                {
                    return(await _geralPersist.GetInfo());
                }
                return(null);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
コード例 #13
0
        public async Task <Cotacao> EnviarOfertaAsync(int idCot, EnviarOfertaDto model)
        {
            var cotacao = await _CotacaoPresist.GetCotacaoByIdAsync(idCot);

            var itensCots = await _CotacaoPresist.GetAllItemCotacaoByIdCotAsync(idCot);

            if (cotacao == null)
            {
                return(null);
            }

            var data = model.DataEntrega.ToString("dd/MM/yyyy");

            cotacao.DataEntrega = data;
            cotacao.status      = 2;
            cotacao.Frete       = model.Frete;
            cotacao.Total       = CalcTotalAsync(itensCots);
            cotacao.Total      += model.Frete;


            FGeralPersist.Update <Cotacao>(cotacao);



            if (await FGeralPersist.SaveChangesAsync())
            {
                return(await _CotacaoPresist.GetCotacaoByIdAsync(idCot));
            }
            return(null);
        }
コード例 #14
0
        public async Task <Biblia> Update(Biblia model)
        {
            try{
                var oldResult = await _geralPersist.GetById(model.Id);

                model.CreatedAt = oldResult.CreatedAt;
                model.UpdatedAt = DateTime.Now;
                model.IsActive  = true;
                _geralPersist.Update <Biblia>(model);
                if (await _geralPersist.SaveChangesAsync())
                {
                    return(await _geralPersist.GetById(model.Id));
                }
                return(null);
            }catch (Exception e) {
                throw new Exception(e.Message);
            }
        }
コード例 #15
0
ファイル: LoteService.cs プロジェクト: vsandrade/ProEventos
        public async Task <LoteDto[]> SaveLotes(int eventoId, LoteDto[] models)
        {
            try
            {
                var lotes = await _lotePersist.GetLotesByEventoIdAsync(eventoId);

                if (lotes == null)
                {
                    return(null);
                }

                foreach (var model in models)
                {
                    if (model.Id == 0)
                    {
                        await AddLote(eventoId, model);
                    }
                    else
                    {
                        var lote = lotes.FirstOrDefault(lote => lote.Id == model.Id);
                        model.EventoId = eventoId;

                        _mapper.Map(model, lote);

                        _geralPersist.Update <Lote>(lote);

                        await _geralPersist.SaveChangesAsync();
                    }
                }

                var loteRetorno = await _lotePersist.GetLotesByEventoIdAsync(eventoId);

                return(_mapper.Map <LoteDto[]>(loteRetorno));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }