Exemple #1
0
        public async Task <ActionResult> Put(int EventId, EventDtos model)
        {
            try
            {
                var ev = await _repo.GetEventAsyncById(EventId, false);

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

                _mapper.Map(model, ev);

                _repo.uptdate(ev);

                if (await _repo.SaveChargesAsync())
                {
                    return(Created($"/event/{model.Id}", _mapper.Map <EventDtos>(ev)));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Banco de dados Falhou"));
            }
        }
Exemple #2
0
        public async Task <ActionResult> Post(EventDtos model)
        {
            try
            {
                var eventos = _mapper.Map <Event>(model);

                _repo.add(eventos);

                if (await _repo.SaveChargesAsync())
                {
                    return(Created($"/event/{model.Id}", _mapper.Map <Event>(eventos)));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            catch (System.Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $"Banco de dados Falhou {ex.Message}"));
            }
        }