Exemplo n.º 1
0
        public int AddFloor(FloorModel floor)
        {
            using (var connection = new SqlConnection(conS))
            {
                connection.Open();
                var sql = "INSERT INTO Floors(FloorPlan, FloorName, BuildingID) output INSERTED.FloorID VALUES(@FloorPlan, @FloorName, @BuildingID)";
                using (var cmd = new SqlCommand(sql, connection))
                {
                    //TODO FloorID
                    cmd.Parameters.AddWithValue("@FloorPlan", floor.Floorplan);
                    cmd.Parameters.AddWithValue("@FloorName", floor.FloorName);
                    cmd.Parameters.AddWithValue("@BuildingID", floor.BuildingID);

                    int insertedID = (int)cmd.ExecuteScalar();
                    return(insertedID);
                }
            }
        }
Exemplo n.º 2
0
        public FloorModel GetFloorPlanByID(int id)
        {
            FloorModel returnval = new FloorModel();

            using (var connection = new SqlConnection(conS))
            {
                connection.Open();
                var sql = "SELECT * From Floors where FloorID =" + id;
                using (var cmd = new SqlCommand(sql, connection))
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            returnval.BuildingID = reader.GetInt32(2);
                            returnval.FloorName  = reader.GetString(3);
                            returnval.Floorplan  = reader.GetString(1);
                        }
                    }

                    return(returnval);
                }
            }
        }