예제 #1
0
        public async Task <IActionResult> Put(int EventoId, Evento model)
        {
            try
            {
                var evento = await _repo.GetEventoAsyncById(EventoId, false);

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

                _repo.Update(model);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"api/evento/{model.Id}", model));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco Dados Falhou"));
            }

            return(BadRequest());
        }
        public async Task <IActionResult> Put(int EventoId, EventoDto model)
        {
            try
            {
                var evento = await _repo.GetEventoAsyncById(EventoId, false);

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

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

                model.Lotes.ForEach(item => idLotes.Add(item.Id));
                model.RedeSociais.ForEach(item => idRedeSociais.Add(item.Id));

                var lotes = evento.Lotes.Where(
                    lote => !idLotes.Contains(lote.Id)
                    ).ToArray();

                var redesSociais = evento.RedeSociais.Where(
                    rede => !idRedeSociais.Contains(rede.Id)
                    ).ToArray();

                if (lotes.Length > 0)
                {
                    _repo.DeleteRange(lotes);
                }

                if (redesSociais.Length > 0)
                {
                    _repo.DeleteRange(redesSociais);
                }


                _mapper.Map(model, evento);

                _repo.Update(evento);
                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"api/evento/{model.Id}", _mapper.Map <EventoDto>(evento)));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }
            return(BadRequest());
        }
예제 #3
0
        public async Task <IActionResult> Put(int PalestranteId, Palestrante model)
        {
            try
            {
                var palestrante = await _repo.GetPalestranteAsync(PalestranteId, false);

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

                _repo.Update(model);
                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"api/palestrante/{model.Id}", model));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados falhou"));
            }
            return(BadRequest());
        }