Esempio n. 1
0
        public IActionResult AlterarStatus([FromBody] StatusBikeModel model)
        {
            var response = string.Empty;

            if (model.Status)
            {
                if (_bikeService.TravarBikeInCorrida(model.IdUser, ref response))
                {
                    response = "Travada com sucesso";
                    return(Ok(new
                    {
                        status = "Sucess",
                        message = response
                    }));
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(model.IdBike))
                {
                    return(NotFound(new
                    {
                        status = "Failed",
                        message = "idBike invalido!"
                    }));
                }
                if (_bikeService.AlterarStatus(model.IdBike, model.Status, ref response))
                {
                    if (_bikeService.CreateCorrida(model.IdBike, model.IdUser, ref response))
                    {
                        response = "Destravada com sucesso";
                        return(Ok(new
                        {
                            status = "Sucess",
                            message = response
                        }));
                    }
                    _bikeService.AlterarStatus(model.IdBike, true, ref response);
                }
            }


            return(BadRequest(new
            {
                status = "Failed",
                message = response
            }));
        }