Beispiel #1
0
        public async Task <ActionResult <Airplane> > Post([FromServices] IAirplaneAppServico app, AirplaneDTO airplaneDTO)
        {
            airplaneDTO.Validate();
            if (airplaneDTO.Invalid)
            {
                return(BadRequest(new RetornoDTO()
                {
                    Success = false,
                    Message = "Não foi possível cadastrar o airplane",
                    Data = airplaneDTO.Notifications
                }));
            }


            try
            {
                await app.InsertAsync(_mapper.Map <Airplane>(airplaneDTO));

                return(Ok(new RetornoDTO()

                {
                    Success = true,
                    Message = "Airplane cadastrado com sucesso",
                    Data = airplaneDTO
                }));
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task <ActionResult <AirplaneDTO> > Get([FromServices] IAirplaneAppServico app, int id)
        {
            var result = _mapper.Map <Airplane>(app.First(x => x.Id == id));

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

            return(Ok(result));
        }
Beispiel #3
0
        public async Task <ActionResult <AirplaneDTO> > Delete([FromServices] IAirplaneAppServico app, int id)
        {
            var airplane = await app.GetAsync();

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

            app.Delete(x => x.Id == id);

            return(Ok(airplane));
        }
Beispiel #4
0
        public async Task <IActionResult> Put([FromServices] IAirplaneAppServico app, AirplaneDTO airplaneDTO)
        {
            airplaneDTO.Validate();

            if (airplaneDTO.Invalid)
            {
                return(BadRequest(new RetornoDTO()
                {
                    Success = false,
                    Message = "Não foi possível editar airplane",
                    Data = airplaneDTO.Notifications
                }));
            }

            try
            {
                app.Update(_mapper.Map <Airplane>(airplaneDTO));
            }

            catch (DbUpdateConcurrencyException)
            {
                if (!app.Exists(x => x.Id == airplaneDTO.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok(new RetornoDTO()
            {
                Success = true,
                Message = "Airplane editado com sucesso",
                Data = airplaneDTO
            }));
        }
Beispiel #5
0
 public async Task <ActionResult <IEnumerable <AirplaneDTO> > > Get([FromServices] IAirplaneAppServico app)
 {
     return(Ok(_mapper.Map <IEnumerable <Airplane> >(await app.GetAsync())));
 }
Beispiel #6
0
 private bool AirplaneExists([FromServices] IAirplaneAppServico app, int id)
 {
     return(app.Exists(x => x.Id == id));
 }