public IHttpActionResult PostReservas(ReservasModel p)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Reserva.GenerarReserva(p.Reserva_Usuario, p.Consec_Reserva, p.Destino, p.Cant_Boletos, p.TotalCompra, p.Num_Reserva, p.BookingID);

            return(CreatedAtRoute("DefaultApi", new { id = p.RSVID }, p));
        }
Example #2
0
        public ActionResult VerReservasUtilizador()
        {
            ViewBag.LoggedIn = IsLoggedIn();

            var utilizador = (LoginModel)Session[SessionUtilizador];

            var model = new SearchDestinosModel();

            var listaReservas = new List <ReservasModel>();

            var getReservasUser = $@"SELECT 
	                                    rh.data_inicio,
	                                    rh.data_fim,
	                                    rh.nr_hospedes,
	                                    th.preco_unidade,
	                                    tp.designacao,
	                                    h.nome,
	                                    h.classificacao,
	                                    rh.preco_total,
                                        
	                                    CONCAT(h.morada, ', ', h.codigo_postal, ' - ', l.localizacao) as morada,
	
                                        (STUFF((SELECT a.designacao
                                             FROM reserva_servicos rs
		                                     left join artigos a on a.id_artigo = rs.id_artigo 
                                             WHERE rs.id_reserva_hotel = rh.id_reserva_hotel
                                             FOR XML PATH ('')), 1, 2, '')) AS artigos,

	                                    rh.id_reserva_hotel,
                                        rh.apagado

                                        FROM reserva_hotel rh

		                                    left join tarifas_hotel th on th.id_tarifa = rh.id_tarifa_hotel
		                                    left join hotel h on h.id_hotel = th.id_hotel
		                                    left join localizacao l on l.id_localizacao = h.id_localizacao
		                                    left join tipo_quarto tp on tp.id_tipo_quarto = th.id_tipo_quarto

                                            WHERE 1=1
                                                AND rh.id_utilizador = {utilizador.IdUser}
                                            ORDER BY rh.data_inicio DESC";

            using (var connection = new SqlConnection(ConnectionString))
                using (var command = new SqlCommand(getReservasUser, connection))
                {
                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var newReserva = new ReservasModel
                            {
                                IdReserva  = Convert.ToInt32(reader["id_reserva_hotel"]),
                                DataInicio = Convert.ToDateTime(reader["data_inicio"]),
                                DataFim    = Convert.ToDateTime(reader["data_fim"]),

                                NomeHotel      = reader["nome"].ToString(),
                                MoradaCompleta = reader["morada"].ToString(),
                                Classificacao  = reader["classificacao"].ToString(),

                                NrHospedes   = reader["nr_hospedes"].ToString(),
                                TipoQuarto   = reader["designacao"].ToString(),
                                Preco        = reader["preco_total"].ToString(),
                                PrecoUnidade = reader["preco_unidade"].ToString(),
                                Apagado      = Convert.ToBoolean(reader["apagado"])
                            };

                            var sqlGetArtigosreserva = $@"SELECT *
                                         FROM reserva_servicos rs
                                         left join artigos a on a.id_artigo = rs.id_artigo
                                         WHERE rs.id_reserva_hotel = {newReserva.IdReserva}";

                            using (var conn = new SqlConnection(ConnectionString))
                                using (var cm = new SqlCommand(sqlGetArtigosreserva, conn))
                                {
                                    conn.Open();
                                    using (var read = cm.ExecuteReader())
                                    {
                                        while (read.Read())
                                        {
                                            var newArtigo = new ArtigosModel
                                            {
                                                IdArtigo           = Convert.ToInt32(read["id_artigo"]),
                                                Designacao         = read["designacao"].ToString(),
                                                PermitePreMarcacao = Convert.ToBoolean(read["permite_pre_marcacao"]),
                                                Preco = Convert.ToDecimal(read["preco"])
                                            };

                                            newReserva.Artigos.Add(newArtigo);
                                        }
                                    }

                                    conn.Close();
                                }

                            listaReservas.Add(newReserva);
                        }
                    }

                    connection.Close();
                }

            var sqlGetArtigos = "SELECT * FROM artigos;";

            using (var connection = new SqlConnection(ConnectionString))
                using (var command = new SqlCommand(sqlGetArtigos, connection))
                {
                    connection.Open();
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var newArtigo = new ArtigosModel
                            {
                                IdArtigo           = Convert.ToInt32(reader["id_artigo"]),
                                Designacao         = reader["designacao"].ToString(),
                                PermitePreMarcacao = Convert.ToBoolean(reader["permite_pre_marcacao"]),
                                Preco = Convert.ToDecimal(reader["preco"])
                            };

                            model.ListaArtigos.Add(newArtigo);
                        }
                    }

                    connection.Close();
                }

            model.ListaReservas = listaReservas;

            return(View("ViewReservas", model));
        }