Пример #1
0
        public CarrinhoV Parser(Carrinho origin)
        {
            PedidoConverter pedidoConverter = new PedidoConverter();
            SensorConverter sensorConverter = new SensorConverter();

            if (origin == null)
            {
                return(null);
            }
            long idPedido       = 0;
            long idUltimoSensor = 0;

            if (origin.Pedido != null)
            {
                idPedido = origin.Pedido.Id;
            }
            if (origin.UltimoSensor != null)
            {
                idUltimoSensor = origin.UltimoSensor.Id;
            }
            CarrinhoV item = new CarrinhoV
            {
                Id             = origin.Id,
                Nome           = origin.Nome,
                IdUltimoSensor = idUltimoSensor,
                Disponivel     = origin.Disponivel,
                IdPedido       = idPedido,
                HashRota       = origin.HashRota
            };

            return(item);
        }
Пример #2
0
        public IActionResult AtualizarCarrinho([FromBody] CarrinhoV carrinhoV, long id)
        {
            try
            {
                PedidoConverter pedidoConverter = new PedidoConverter();
                SensorConverter sensorConverter = new SensorConverter();
                if (id <= 0)
                {
                    return(StatusCode(400, new ErrorClass(400, "Codigo Invalido", DateTime.Now)));
                }
                var item = (Carrinho.FindById(id));
                if (item == null)
                {
                    return(StatusCode(404, new ErrorClass(404, "Sensor não encontrado", DateTime.Now)));
                }

                if (!string.IsNullOrWhiteSpace(carrinhoV.Nome))
                {
                    item.ChangeName(carrinhoV.Nome);
                }
                if (carrinhoV.IdPedido != 0)
                {
                    item.ChangePedido(Pedido.FindById(carrinhoV.IdPedido));
                }

                if (carrinhoV.IdUltimoSensor != 0)
                {
                    item.ChangeUltimoSensor(Sensor.FindById(carrinhoV.IdUltimoSensor));
                }

                item.UpdateCarrinho();

                return(StatusCode(200, _converter.Parser(item)));
            }
            catch (MercurioCoreException ex)
            {
                return(StatusCode(400, new ErrorClass(400, ex.Message, DateTime.Now)));
            }
            catch (DBConnectionException ex)
            {
                return(StatusCode(500, new ErrorClass(500, ex.Message, DateTime.Now)));
            }
        }
Пример #3
0
 public PedidoController(IConfiguration configuration)
 {
     _converterPedido = new PedidoConverter();
     _itemConverter   = new ItemConverter();
     _config          = configuration;
 }