コード例 #1
0
        private bool VerificaRepetido(int eventoSelecionadonumero, string[] dados)
        {
            var listaEventos = EventoVm.ListarEventos();

            if (!listaEventos.Any())
            {
                return(false);
            }
            var itemEvento = listaEventos.FirstOrDefault(x => x.Numero != eventoSelecionadonumero);

            return(itemEvento != null);
        }
コード例 #2
0
        private bool VerificaExistencia()
        {
            var listaEventos = EventoVm.ListarEventos();

            if (!listaEventos.Any())
            {
                return(false);
            }
            var itemEvento = listaEventos.FirstOrDefault(x =>
                                                         x.GP == Gp && x.Grid.Equals(Grid) && x.Posicao.Equals(Posicao));

            return(itemEvento != null);
        }
コード例 #3
0
        private string GeraPontuacao()
        {
            var maxId          = 0;
            var listaPontuacao = EventoVm.ListarEventos();

            if (listaPontuacao.Any())
            {
                maxId = listaPontuacao.Max(x => x.Numero);
            }

            maxId++;

            return(maxId.ToString());
        }
コード例 #4
0
        public async Task <IActionResult> Post(EventoVm model)
        {
            try
            {
                var evento = _mapper.Map <Evento>(model);
                _repo.Add(evento);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/eventos/{model.Id}", _mapper.Map <EventoVm>(evento)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }
            return(BadRequest());
        }
コード例 #5
0
        public async Task <IActionResult> Put(int id, EventoVm model)
        {
            try
            {
                var evento = await _repo.GetEventoAsyncById(id);

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

                var idLotes        = new List <int>();
                var idRedesSociais = new List <int>();

                model.Lotes.ForEach(l => idLotes.Add(l.Id));
                model.RedesSociais.ForEach(rs => idRedesSociais.Add(rs.Id));

                var lotes        = evento.Lotes.Where(l => !idLotes.Contains(l.Id)).ToArray();
                var redesSociais = evento.RedesSociais.Where(rs => !idRedesSociais.Contains(rs.Id)).ToArray();

                if (lotes.Any())
                {
                    _repo.DeleteRange(lotes);
                }
                if (redesSociais.Any())
                {
                    _repo.DeleteRange(redesSociais);
                }

                _mapper.Map(model, evento);

                _repo.Update(evento);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/eventos/{model.Id}", _mapper.Map <EventoVm>(evento)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }
            return(BadRequest());
        }